I've just ran into a python code that I cannot explain its behavior. The lines are the followings:
def f(a, list=[]):
for i in range(a):
list.append(i*i)
print(list)
f(3)
f(2, [1,2])
f(2)
The output of the calls are:
[0, 1, 4]
[1, 2, 0, 1]
[0, 1, 4, 0, 1]
Why the first list instance is not destroyed and the third call simply returns [0, 1]? What python rule am I missing?
thanks