Python: Internal Integer Object Array

-5 to 256

nick3499
nick3499
Aug 27, 2017 · 1 min read

Python maintains an internal integer object array for integers between -5 and 256. Which explains why the comparison c is d below evaluates to False:

>>> a = 200 + 56
>>> b = 256
>>> c = 200 + 57
>>> d = 257
>>> a == b
True
>>> a is b
True
>>> c == d
True
>>> c is d
False

is compared identities of objects, or their memory addresses. == compared numerical equality of objects.

)
Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade