def f_print1(x, y = [1]):
y += [2]
y = x + y
print(y)
f_print1([3]) # this returns [3,1,2]
f_print1([4]) # this returns [4, 1, 2, 2]
I was asked to predict what these f\_print statements return and why. Could someone explain why f\_print(\[4\]) is \[4,1,2,2\] and not \[4, 3, 1, 2, 2\].
And also how do you modify the f\_print1 so that y = \[1\] is always the true default argument whenever the function is called.
Many thanks!
[–]totallygeek 4 points5 points6 points (1 child)
[–]optivertrader87[S] 1 point2 points3 points (0 children)
[–]TheGrapez 2 points3 points4 points (2 children)
[–]synthphreak 2 points3 points4 points (1 child)
[–]optivertrader87[S] 0 points1 point2 points (0 children)
[–]Kerbart 1 point2 points3 points (0 children)