I have been doing some readings and thought about this code:
def change(c, n: int) -> None:
c.x = n
class Value:
x = 5
m = Value()
change(Value, 3)
print(m.x)
change(m, 1)
change(Value, 2)
print(m.x)
The output of this code is:
- 3
- 1
So what I assumed is for the 3, m & Value are aliased but changing m's attribute breaks this. I couldn't confirm this by running id() - it turned out m and value always had different ids.
Can someone explain what's going on?