def f1(a,L=[]):
if a==1:
print(a,L)
else:
L.append(a)
return L
def f2(a,L=[]):
if a==1:
print(a,L)
else:
L=[3]
return L
calling these two functions yield these results:
f1(2) -> [2]
f1(1) -> 1 [2]
f2(2) -> [3]
f2(1) -> 1 []
That really makes me confused, if L will not loss if value after calling, why f2(1) does not return 1 [3]? Anyone can explain the argument value store or initialization schema in python?