This is python code.
for e in range(-10, 10):
exec('x=%d'% e)
exec('y=%d'% e)
print e, id(x), id(y), x is y
I expected the print statement shows only Trues.
But it is not. under -5, that shows False.
Result is
-10 38832080 38832056 False
-9 38832032 38832080 False
-8 38832056 38832032 False
-7 38832080 38832056 False
-6 38832032 38832080 False
-5 30857416 30857416 True
-4 30857392 30857392 True
-3 30857368 30857368 True
-2 30857344 30857344 True
-1 30857320 30857320 True
0 30857296 30857296 True
1 30857272 30857272 True
2 30857248 30857248 True
3 30857224 30857224 True
4 30857200 30857200 True
5 30857176 30857176 True
6 30857152 30857152 True
7 30857128 30857128 True
8 30857104 30857104 True
9 30857080 30857080 True
Why exec assigns different id to x and y respectively under -5?
CPython caches small integers between -5 and 256. See PyInt_FromLong: