3 ms·
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
by sherjilozair 12y ago
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.
- ShinyCyril 12y agoThis has bitten me more times than I'd care to admit.