Re:Ask HN: If you're “ridiculously in love with Python”, do ...
by hyperbovine on Wednesday January 21, 2015 @10:34AM
(#8923488)
Can someone elaborate on this? I thought I had seen all the Python idioms but this one is new to me.
[ Parent
| on HN ]
Re:Ask HN: If you're “ridiculously in love with Python”, do ...
by sherjilozair on Wednesday January 21, 2015 @10:40AM
(#8923515)
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.
Re:Ask HN: If you're “ridiculously in love with Python”, do ...
by ShinyCyril on Wednesday January 21, 2015 @11:46AM
(#8923868)
This has bitten me more times than I'd care to admit.