Static variable vs Class variable

Laszlo Nagy gandalf at shopzeus.com
Tue Oct 9 13:14:37 EDT 2007


> Your question "is variable a 
> static or class variable?" has no real answer. After running the 
> increment() method on a descendant class, e.g. Child1 will rebind the 
> name Child1.a, creating a new name in the namespace of the class. So the 
> variable Foo.a is still there, but you are accessing Child1.a instead.
>   
Please notice, that theoretically there is no way to "change the value" 
of Foo.a in any way, because this is a NAME that references to an 
IMMUTABLE OBJECT. It means that you can only rebind the variable. You 
cannot change its value, because when we are talking about its value, we 
mean the state of the referenced object. The object referenced by the 
name is an integer instance, namely it is "one". The object "one" always 
remains "one", this cannot be changed. You can add one to one, and you 
will get two, but that is another object.

(I'm sorry, probably you already knew this.)

  Laszlo




More information about the Python-list mailing list