I'm trying to grasp on the idea on how the class variables work. And to my knowledge class variables are shared between the class instances (objects).
So within THAT idea, if I change the class variable, the value should change to all the class instances...
...BUT, this seems not to be always the case.
Below is an simplified example:
name = "Dog"
a1 = A()
a2 = A()
# These both change the value only for an instance
a1.name = "Cat"
a2.name += " is an animal"
number = 0
b1 = B()
b2 = B()
# Again only changes value for an instance
b1.number = 2
# This is the weird one.
lista = 
c1 = C()
c2 = C()
# Changes the value for BOTH/ALL instances.
# But this one only changes the value for an instance.
c1.lista = [1, 2, 3]
Class variables are shared between instances until the moment you assign to an instance variable by the same name. (As an aside, this behavior is useful for declaring defaults in inheritance situations.)
>>> class X: ... foo = "foo" ... >>> a = X() >>> b = X() >>> c = X() >>> c.foo = "bar" >>> id(a.foo) 4349299488 >>> id(b.foo) 4349299488 >>> id(c.foo) 4349299824 >>>
Your list example mutates the shared instance first, then reassigns a new value to
c2.lista remains the shared instance.