, , a a. :
>>> class Foo(object):
... a = 10
...
>>> c = Foo()
>>> c.a
10
>>> c.a = 100
>>> c.a
100
>>> Foo.a
10
>>> del c.a
>>> c.a
10
>>>
The difference is that it exists as a record in Foo.__dict__, and the other exists as a record in c.__dict__. When you turn to instance.attribute, it returns instance.__dict__['attribute']if it exists, and if not, then type(instance).__dict__['attribute']. Then the superclasses of the class are checked, but this gets a little complicated.
But, in any case, the main thing is that it does not have to be this or that. A class and an instance can have different attributes with the same name, because they are stored in two separate dicts.
source
share