1 00:00:07,910 --> 00:00:13,320 The fact that optional parameters' default values are only evaluated once, 2 00:00:13,320 --> 00:00:16,260 can lead to some unintuitive outcomes. 3 00:00:16,260 --> 00:00:19,485 So, here, we define a function that has two arguments, 4 00:00:19,485 --> 00:00:25,245 a and L. L's default value is an empty list. 5 00:00:25,245 --> 00:00:30,020 Now, note again that because this value is only evaluated once, 6 00:00:30,020 --> 00:00:34,750 what that means is that we have an empty list that 7 00:00:34,750 --> 00:00:40,370 lives somewhere in the frames in objects as the default value for L. So, 8 00:00:40,370 --> 00:00:43,375 here after we defined our function f, 9 00:00:43,375 --> 00:00:47,255 then we first print out f called with the value one. 10 00:00:47,255 --> 00:00:53,150 Now, in the body of f we actually mutate the value of L. So, what that means, 11 00:00:53,150 --> 00:00:56,975 is that when we call f on line five we pass in one for 12 00:00:56,975 --> 00:01:02,650 a and L is going to be that empty list that we created right here. 13 00:01:02,650 --> 00:01:09,160 When we run line two to say L.append a then we append one 14 00:01:09,160 --> 00:01:15,655 to our empty list and now our list is a list that has one item whose value is one. 15 00:01:15,655 --> 00:01:21,230 Now, on line three we return that list L. But, 16 00:01:21,230 --> 00:01:26,720 the thing to note here is that even though this list is going to go away in CodeLens, 17 00:01:26,720 --> 00:01:31,525 it actually keeps its value of a list that has one item whose value is one. 18 00:01:31,525 --> 00:01:35,595 So, even though this disappears in CodeLens, 19 00:01:35,595 --> 00:01:42,775 by the time we get to line six this list still has the value one. 20 00:01:42,775 --> 00:01:48,200 So, now, on line six when we call f with a equals two, 21 00:01:48,200 --> 00:01:55,930 then you can see that L is this list that has one item in it already. 22 00:01:55,930 --> 00:02:03,560 So, now, on line two when we append a to our list we add two onto this list. 23 00:02:03,560 --> 00:02:05,555 So, we're going to say, 24 00:02:05,555 --> 00:02:10,720 list is now a list that has one and two in it. 25 00:02:10,720 --> 00:02:16,390 So, if we kept calling our function f to add new values to our list, 26 00:02:16,390 --> 00:02:23,420 then we would get a longer and longer list as our default value for L. So, here, 27 00:02:23,420 --> 00:02:28,220 by the time we get to line seven and we call f with three, 28 00:02:28,220 --> 00:02:33,260 then when we call this function our list L already has two values in it, 29 00:02:33,260 --> 00:02:38,630 and on line two we add three on as a third value in our list. 30 00:02:38,630 --> 00:02:43,400 So, the important thing to note again here is that as 31 00:02:43,400 --> 00:02:50,155 our default value gets mutated it affects feature calls to this function f. Now, 32 00:02:50,155 --> 00:02:51,930 an important distinction here, 33 00:02:51,930 --> 00:02:56,560 is distinguishing between lists that are different objects, 34 00:02:56,560 --> 00:02:59,525 but have the same value versus this list, 35 00:02:59,525 --> 00:03:01,235 which is the same object. 36 00:03:01,235 --> 00:03:04,240 So, for example, on lines eight and nine, 37 00:03:04,240 --> 00:03:08,270 we pass in two different values for L. On line eight, 38 00:03:08,270 --> 00:03:12,920 we pass in a list that has the string "Hello" as its one item. 39 00:03:12,920 --> 00:03:17,365 On line nine, we pass in a list that looks identical, 40 00:03:17,365 --> 00:03:20,165 but because these are separate expressions, 41 00:03:20,165 --> 00:03:22,550 then these are actually separate objects. 42 00:03:22,550 --> 00:03:26,195 What that means, is that by the time we get to line 43 00:03:26,195 --> 00:03:30,770 eight and we print out the value of f called with a equals four, 44 00:03:30,770 --> 00:03:34,100 and L equals the list with the item "Hello." 45 00:03:34,100 --> 00:03:38,390 Then, when we actually call L.append a, 46 00:03:38,390 --> 00:03:40,960 then we're mutating this list, 47 00:03:40,960 --> 00:03:45,270 and that has no effect on this list. 48 00:03:45,270 --> 00:03:50,160 So, here we're mutating this list to add four onto it, 49 00:03:50,560 --> 00:03:53,545 which you can see here, 50 00:03:53,545 --> 00:03:57,075 and then when we get to line nine, 51 00:03:57,075 --> 00:03:59,710 then we're mutating a different list. 52 00:03:59,710 --> 00:04:04,700 So, note again here that we have a list 53 00:04:04,700 --> 00:04:11,600 whose only value is "Hello" it doesn't have the four that we added on to this list. 54 00:04:11,600 --> 00:04:15,150 That's all for now, until next time.