Why float('Nan') == float('Nan') is False

Joe Pfeiffer pfeiffer at cs.nmsu.edu
Wed Feb 13 14:33:31 EST 2019


ast <none at gmail.com> writes:

> Hello
>
>>>> float('Nan') == float('Nan')
> False
>
> Why ?
>
> Regards

Others have given the real answer -- IEEE says so, and the people who
wrote the standard are smarter than me.  All the same, this is my take
on the reason for it:  NaN is specifically a representation for "this
has no value".  The == operator compares the values of its operands;
something that has no value can't == anything, including itself.



More information about the Python-list mailing list