0
>>> 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?

jonrsharpe
  • 115,751
  • 26
  • 228
  • 437
4words
  • 13
  • 4
  • Should I delete my question? – 4words Nov 20 '16 at 10:10
  • In general, no: most duplicates stay around. Having multiple copies of the same question with different wording is useful as search fodder, because people looking for an answer may use different wording too. – bluefoggy Nov 20 '16 at 10:14

1 Answers1

-3

As the documentation notes

Two objects with non-overlapping lifetimes may have the same id() value.

zabeltech
  • 963
  • 11
  • 27