I'm trying to teach a reason for the need of instance variables and using self. So I came up with the following example. However, it's not going the way I thought it would, haha. I have come to appeal to you all to answer my question: although I am changing the class variable, how come the last print statement with x.one doesn't print out -1 as well?
class example():
one = 1
two = 2
# Creating 2 'example' objects, x and y
x = example()
y = example()
print("x is: ", x.one, "y is: ", y.one) # output: x is 1, y is 1
# From the print statement, we'll see that changing one class object does not affect another class object
x.one = 0
print("x is: ", x.one, "y is: ", y.one) # output: x is 0, y is 1
# But what if we changed the class itself?
example.one = -1
print("x is: ", x.one, "y is: ", y.one) # output: x is 0, y is -1
My guess is that it has something to do with me altering x.one's value in the block above, which makes x.one possibly having a new location in memory instead of referencing example.one's location in memory.
If you could give me a more detailed reason, I would very much appreciate it and would be able to pass on the knowledge to my student.