Static variable vs Class variable

Marc 'BlackJack' Rintsch bj_666 at gmx.net
Tue Oct 9 19:26:50 EDT 2007


On Tue, 09 Oct 2007 22:43:16 +0000, Steven D'Aprano wrote:

> On Tue, 09 Oct 2007 19:46:35 +0000, Marc 'BlackJack' Rintsch wrote:
> 
>> On Tue, 09 Oct 2007 18:08:34 +0000, Steven D'Aprano wrote:
>> 
>>>>>> L = []
>>>>>> id(L)
>>> 3083496716L
>>>>>> L += [1]
>>>>>> id(L)
>>> 3083496716L
>>> 
>>> It's the same L, not rebound at all.
>> 
>> It *is* rebound.  To the same object, but it *is* assigned to `L` and
>> not just mutated in place.
> 
> Picky picky.
>
> Yes, technically there is an assignment of L to itself. I was sloppy to 
> say "not rebound at all", because when you write an augmented assignment 
> method you have to return self if you want to implement in-place 
> mutation. But I hardly call "rebinding to itself" any sort of rebinding 
> worth the name :)

Maybe picky but that detail was the source of the OPs confusion because it
introduced a new attribute on the subclass.

Ciao,
	Marc 'BlackJack' Rintsch



More information about the Python-list mailing list