I have two classes as below:
class foo:
def __init__(self):
self.val = 10
class foo2:
def __init__(self):
self.val = 1000
When I copy an instance of class foo into a variable and then change a value of class foo, the variables changes. This is because the foo is a reference type and every change in foo changes its instances as well.
f = foo()
b = f
print(b.val)
f.val = 20
print(b.val)
>> 10
>> 20
But if I copy the class foo2 into class foo, the variable b does not change to 1000. What is the explanation for this?
f = foo2()
print(f.val)
print(b.val)
>> 1000
>> 20