def f(a, L=[]):
L.append(a)
return L
print(f(1))
print(f(2))
print(f(3))
I don't understand why in the above case the list L is initialized only one time, while in the case below the list is initalized each time the function is called
def f(a, L=None):
if L is None:
L = []
L.append(a)
return L
print(f(1))
print(f(2))
print(f(3))