'Why are two instances of "object" considered non-identical although their "id()" are the same? [duplicate]
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 wherexis 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?
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
