According to the Python Language Reference:
The ‘
is
’ operator compares the identity of two objects; theid()
function returns an integer representing its identity.CPython implementation detail: For CPython,
id(x)
is the memory address wherex
is stored.
However:
>>> object() is object()
False
>>> id(object()) == id(object())
True
How is this consistent with the documented behavior? Why are the two objects considered non-identical although their id()
are the same? Why is object() is object()
considered False
although id(object()) == id(object())
is True
?