I came across this phrase:
"Python keeps an array of ints between
-5
and256
. When you create an int in that range, you get a reference to a pre-existing object"
You can verify with this code:
def check(n,d):
a = b = n
a -= d
b -= d
return a is b
Now, check(500,10)
returns False
. But check(500,300)
returns True
. Why does Python compiler would do such a thing? Isn't it a perfect recipe for bugs?