Possible Duplicate:
“Least Astonishment” in Python: The Mutable Default Argument
def test(mylist=['a']):
mylist.append(1.)
print mylist
test()
test()
Is giving me the following result:
['a', 1.0]
['a', 1.0, 1.0]
Why is this the case? I would expect:
['a', 1.0]
['a', 1.0]
The test is called two times and eachtime mylist is created as a local variable.