I have the following concern in Python:
a = 1
b = a
b = 2
print(a)
From what I understand, b
is a new variable that uses the value of a
. Thus, when the value of b
is changed, that does not affect a
. So, print(a)
should yield 1
.
class Object:
def __init__(self):
self.value = 0
a = Object()
a.value = 1
b = a
b.value = 2
print(a.value)
However, in this instance, a
would print 2
. Why is this? How do I make it so that a.value
will still be 1
instead of 2
?