Issue 18127: Strange behaviour with default list argument (original) (raw)
I'd like to nominate this piece of code as candidate for the next round of "Most unexpected python behaviour" awards:
def foo(a, x = []):
x.append(a)
return x
print(foo(1))
print(foo(2))
I expected the output to be: [1] [2] but I get: [1] [1, 2]
Bug? (If not, I'd love to read the rationale for this behaviour...)