[issue30932] Identity comparison ("is") fails for floats in Python3 but works in Python2
Steven D'Aprano
report at bugs.python.org
Fri Jul 14 13:40:38 EDT 2017
Steven D'Aprano added the comment:
This is not a bug. Whether Python allocates one, or two, float objects for a particular floating point value is dependent on the implementation and not a language guarantee. The language does not promise that two floats with the value 7.3 will be the same object, only that they are equal.
In Python 3.5 on Linux, I can see:
py> 7.3 is 7.3
True
py> x = 7.3
py> y = 7.3
py> x is y
False
*but your results may be different*. There is no language promise here, except that `x is x` must be true.
----------
nosy: +steven.daprano
resolution: -> not a bug
stage: -> resolved
status: open -> closed
_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue30932>
_______________________________________
More information about the Python-bugs-list
mailing list