>>> x = 5
>>> id(x)
40186104
>>> x += 6
>>> id(x)
40185960
>>> z = 5
>>> id(z)
40186104
Python deletes all objects once there are no more references to it.
Here when x
is bound to 11
, there are no more references to 5
. So I suppose it is deleted. Then why does its id remain the same after reallocation?
The other possibility is that 5
is not deleted at all. If so, then why?