class Circle:
a = 2
b = a
#print class variables
print(Circle.a)
print(Circle.b)
2
2
# updating class variable a to value 100
Circle.a = 100
# printing updated class variables
print(Circle.a)
print(Circle.b)
100
2
Why isn`t class variable b also updating to 100 ? Can I change the variable without a setter method ?
listordict. Setato alistand thenappendtobto see that they are now 'linked'.aandbboth point to the same value (2) in memory (assignment never copies data). Then,ais reassigned to point to the value100. Names are reassigned independently. You would observe exactly the same behavior for a list or dict.