I'm running:
Python 2.7.8 (default, Oct 6 2017, 09:25:50)
GCC 4.1.2 20070626 (Red Hat 4.1.2-14) on Linux 2
As per the documentation:
The operators
is
andis not
test for object identity:x is y
isTrue
if and only ifx
andy
are the same object.
To get an object's identity, we can use the id
function.
If we open up a new REPL we can see that 300
and -6
have the same identity (on CPython, this means that both refer to the same memory address):
>>> id(300)
94766593705400
>>> id(-6)
94766593705400
Note that the actual values may differ from execution to execution, but they are always equal.
However, doing 300 is -6
yields False
:
>>> 300 is -6
False
I have a couple of questions:
- Why (and how) do
300
and-6
share the same identity? - If they do, why is
300 is -6
yieldingFalse
?