I want to preface this by saying that I know the difference between ==
and is
one is for references and the other is for objects. I also know that python caches the integers in the range (-5, 256)
at startup so they should work when comparing them with is
.
However I have seen a strange behaviour.
>>> 2**7 is 2**7
True
>>> 2**10 is 2**10
False
This is to be expected, 2**7
is 128
and 2**10
is 1024
, one is in the interval (-5, 256)
and the other is not.
However...
>>> 10000000000000000000000000000000000000000 is 10000000000000000000000000000000000000000
True
Why does this return True
? It is obviously a value WAY above any kind of caching interval and 2**10 is 2**10
clearly showed that is
does actually not work on integers above 256
. So... why does this happen?