Python: Internal Integer Object Array

-5 to 256

nick3499
1 min readAug 27, 2017

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.

--

--

nick3499
nick3499

Written by nick3499

coder of JavaScript and Python

No responses yet