Dictionaries and lists defined directly under the class definition act as static (e.g. this question)
How come other variables such as integer do not?
>>> class Foo():
bar=1
>>> a=Foo()
>>> b=Foo()
>>> a.bar=4
>>> b.bar
1
>>> class Foo():
bar={}
>>> a=Foo()
>>> b=Foo()
>>> a.bar[7]=8
>>> b.bar
{7: 8}
They are all class variables. Except for when you assigned
a.bar=4creating an instance variable. Basically Python has a lookup order on attributes. It goes:So if you have
This is a variable on the class Foo. Once you do
you have created a new variable on the object
awith the namebar. If you look ata.__class__.baryou will still see 1, but it is effectively hidden due to the order mentioned earlier.The dict you created is at the class-level so it is shared between all instances of that class.