Hacker News
new
|
past
|
comments
|
ask
|
show
|
jobs
|
submit
login
hyperbovine
on Jan 21, 2015
|
parent
|
context
|
favorite
| on:
Ask HN: If you're “ridiculously in love with Pytho...
Can someone elaborate on this? I thought I had seen all the Python idioms but this one is new to me.
sherjilozair
on Jan 21, 2015
[–]
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
on Jan 21, 2015
|
parent
[–]
This has bitten me more times than I'd care to admit.
Guidelines
|
FAQ
|
Lists
|
API
|
Security
|
Legal
|
Apply to YC
|
Contact
Search: