I have a simple Point class with attributes z, y and z. I first instantiate the first object:
point1 = Point(1, 2, 3)
Now I instantiate my second point like this:
point2 = Point(point1.x, 3, 4)
When I run id() on the points and attributes I get this
id(point1): 1565146411848: x: 1, y: 2, z: 3 id(point1.x): 140711867415616
id(point2): 1565146435400: x: 1, y: 3, z: 4 id(point2.x): 140711867415616
Clearly the two Point objects are unique, however, they seem to share the same x.
Now, when I change, say point2.x = 900, the following happens:
id(point1): 1565146411848: x: 1, y: 2, z: 3 id(point1.x): 140711867415616
id(point2): 1565146435400: x: 900, y: 3, z: 4 id(point2.x): 1565143647248
point2.x is now differnent to point1.x. So I assume at the point of assignment under these conditions, a new instance of the attribute x is created? I am not clear what the rules of python is here, I have always understood that assignment does not cause instantiation, however it would appear as though this is exactly what happens here? How does this work?