def a(b=[]):
b.append(1)
print b
Now if you do, a()
a()
you might expect to see [1]
[1]
but you will actually see [1]
[1, 1]
The list is not created at function call time, but at function definition time. def a(b=[]):
b.append(1)
print b
Now if you do, a()
a()
you might expect to see [1]
[1]
but you will actually see [1]
[1, 1]
The list is not created at function call time, but at function definition time.