first = 30
second = first
first = 20
print("first: ", first, "second: ", second)
# first: 20 second: 30
In the above example, it seems the variable second
points directly to the memory address for 30, and when first
is reassigned it therefore has no effect on second
.
class Circle:
pi = 3.1419
circle1 = Circle()
circle2 = Circle()
circle2.pi = 10
print(Circle.pi, circle1.pi, circle2.pi)
# 3.1419 3.1419 10
Circle.pi = 40
print(Circle.pi, circle1.pi, circle2.pi)
# 40 40 10
In the above example however, when I assign 40
to Circle.pi
, it has an affect on circle1.pi
because circle1.pi
was pointing to Circle.pi
instead of the memory address for 3.1419
.