4 ms·
As a side note, I have seen the `def a(b=[])` being used to have a static variable in a function.
by pwnna 12y ago
As a side note, I have seen the `def a(b=[])` being used to have a static variable in a function.
- hyperbovine 12y agoCan someone elaborate on this? I thought I had seen all the Python idioms but this one is new to me.
- sherjilozair 12y agodef 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.