Static variable vs Class variable
Diez B. Roggisch
deets at nospam.web.de
Tue Oct 9 16:27:47 EDT 2007
Steven D'Aprano schrieb:
> On Tue, 09 Oct 2007 19:23:37 +0200, Diez B. Roggisch wrote:
>
>> Your believes aside, this is simply wrong. The statement
>>
>> a += x
>>
>> always leads to a rebinding of a to the result of the operation +.
>
> Not true.
Yes, it is.
>>>> L = []
>>>> id(L)
> 3083496716L
>>>> L += [1]
>>>> id(L)
> 3083496716L
>
> It's the same L, not rebound at all.
Just because the __iadd__-operation in the list implemented chose to
returen a reference to itself - certainly a sensible choice, I never
doubted that - doesn't change the fact that python rebinds the name on
the left with whatever __iadd__ returned.
Diez
More information about the Python-list
mailing list