Default values for arguments [duplicate]
问题 This question already has answers here : Closed 8 years ago . Possible Duplicate: “Least Astonishment” in Python: The Mutable Default Argument Consider the following function: def foo(L = []): L.append(1) print L Each time I call foo it will print a new list with more elements than previous time, e.g: >>> foo() [1] >>> foo() [1, 1] >>> foo() [1, 1, 1] Now consider the following function: def goo(a = 0): a += 1 print a When invoking it several times, we get the following picture: >>> goo() 1 >