I learned that id(1) always same because of interning mechanism.
>>> id(1)
14710976
>>> id(1)
14710976
>>> 5
>>> id(1)
14710976
>>>
But when i try id(2000000000), it will intern too if execute id(2000000000) continuosly, but this id will changed after it execute something else (e.g. give print a number). And the id has been reuse every three times of id changing.
As you can see on the session below, 3 ids, 142989240, 142989252, 142989132:
>>> id(2000000000)
142989240
>>> id(2000000000)
142989240
>>> 5
5
>>> id(2000000000)
142989252
>>> id(2000000000)
142989132
>>> 5
5
>>> id(2000000000)
142989132
>>> 5
5
>>> id(2000000000)
142989240
>>> 5
5
>>> id(2000000000)
142989252
>>> 5
5
>>> id(2000000000)
142989132
>>>
1st question: Why python reuse the id every 3 times? Is there any concerns of python contributors agree to choose 3, not 2 or 4? In which file in the python source code can i find out the 3 times implementation?
2nd question:
I find out if interned two times
>>> id(2000000000)
161535928
>>> id(2000000000)
161535928
>>> 5
5
>>> id(2000000000)
161535940
>>> 5
5
>>> id(2000000000)
161535820
or interned five times
>>> id(2000000000)
161195960
>>> id(2000000000)
161195960
>>> id(2000000000)
161195960
>>> id(2000000000)
161195960
>>> id(2000000000)
161195960
>>> 5
5
>>> id(2000000000)
161195972
>>> 5
5
>>> id(2000000000)
161195852
, then the next 2 ids, will ALWAYS end with the same single digits. As you can see on the session above, after id(2000000000) interned, both 161535940 and 161535820 end with digit 0. After id(2000000000) interned 5 times, both 161195972 and 161195852 end with digit 2.
But if interned once/three/four/six times, then i always get 3 ids which was ending in different digits. As you can see on the session below, the interpreter session shows that 140613560, 140613476, and 140613572 ending with 0, 6, 2 respectively.
>>> id(2000000000)
140613560
>>> id(2000000000)
140613560
>>> id(2000000000)
140613560
>>> 5
5
>>> id(2000000000)
140613476
>>> 5
5
>>> id(2000000000)
140613572
So my question is, why this constant behavior occur and how it implemented?
3rd question:
Related to 2nd question, if intern two or five times, there are special behavior occur.
>>> id(2000000000)
141371320
>>> id(2000000000)
141371320
>>> 5
5
>>> id(2000000000)
141371332
>>> 5
5
>>> id(2000000000)
141371212
>>>
>>> id(2000000000)
141371212
>>> 5
5
>>> id(2000000000)
141371236
>>> 5
5
>>> id(2000000000)
141371320
Look at the middle of the session above, i press ENTER and leave empty >>> , and the 3 ids reused (refer to 1st question) is changed ! 141371320 -> 141371332 -> 141371212 become 141371212 -> 141371236 -> 141371320. And i reproduced the step and find out the total is 4 ids candidates in the sequence of 141371320 -> 141371332 -> 141371212 -> 141371236
My question was, why this special behavior exist?