[Python-Dev] == on object tests identity in 3.x
antoine at python.org
Wed Jul 9 15:21:26 CEST 2014
Le 09/07/2014 00:21, Stephen J. Turnbull a écrit :
> Steven D'Aprano writes:
> > I don't think so. Floating point == represents *numeric* equality,
> There is no such thing as floating point == in Python. You can apply
> == to two floating point numbers, but == (at the language level)
> handles any two numbers, as well as pairs of things that aren't
> numbers in the Python language.
This is becoming pointless hair-splitting.
>>> float.__eq__(1.0, 2.0)
>>> float.__eq__(1.0, 2)
>>> float.__eq__(1.0, 1.0+0J)
>>> float.__eq__(1, 2)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: descriptor '__eq__' requires a 'float' object but received a
Please direct any further discussion of this to python-ideas.
More information about the Python-Dev