Python: Internal Integer Object Array
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.