3 ms·
`is` means "do these things reside in the same location in memory?", and the runtime is merely required to give a plausible answer. For inequivalent values or
by Veedrac 11y ago
`is` means "do these things reside in the same location in memory?", and the runtime is merely required to give a plausible answer.
For inequivalent values or `True`, `False` and `None`, the result is defined. Identity is also preserved across assignment. For everything else, the answer is "whatever the runtime feels like". PyPy, for instance, will always say True for integers and floats.
It's not just hard to predict - it's inherently unpredictable. The runtime gets free reign as long as you can't prove that it's lying.