Summary Are two different references to the same integer value the same object? The answer: sometimes.
In Python, everything is an object. These semantics are predictable for the most part -- until they aren't. Here's a short but confusing snippet of Python 3 code, running from Ubuntu 9.04. Can you surmise why this inconsistency happens?
>>> a = 500 >>> b = 500 >>> a is b False >>> c = 200 >>> d = 200 >>> c is d True
In Python, is tests for identity, not equality. x is y if and only if x and y reference the same thing. Although a and b have the same value, they are distinct objects, and so comparing the two yields False, as one might expect.
But then we're confronted with the second case. It's precisely identical to the first, just with a different assigned value. Yet it produces the opposite result. How can this be?
The key to this puzzle lies in a peculiar implementation detail of CPython, the de facto Python implementation. As we said earlier, in Python, everything is an object, even literals. Logically, that means that two different instances should be distinct from each other, as in the first case above.
But in CPython, when you create an integer literal in the range [-5, ..., 256], it's actually cached for performance reasons. Further references to the same literal are identical references to the existing literal, not new references. Thus c and d refer to the same cached instance, and the result is True.
Because of another implementation detail, two literals with the same value that are in the same compilation unit will reference the same object. Comparing literals directly results in True in both cases, as we see here:
>>> 200 is 200 True >>> 500 is 500 True
More importantly, however, this illustrates the danger when is is mistakenly used to compare value equality instead of reference equality. Had you used == instead, the results are precisely what you'd expect:
>>> a = 500 >>> b = 500 >>> a == b True >>> c = 200 >>> d = 200 >>> c == d True


