If I define a simple class
class someClass():
var = 1
x = someClass()
someClass.var = 2
This will make x.var
equal 2. This is confusing to be because normally
something akin to this like:
a = 1
b = a
a = 2
will leave b intact as b==1
. So why is this not the same with class variables? Where is the difference? Can call all class variables mutable?
In a way the class variables work more like assigning a list to a=[1]
and doing a[0]=2
.
Basically the problem is how is x.var
acessing someClass.var it must be something different then is used when two variables are set equal in python. What is happening?