FW: Why float('Nan') == float('Nan') is False
avigross at verizon.net
Thu Feb 14 22:36:26 EST 2019
I can see why you may be wondering. You see the nan concept as having a
specific spelling using all lowercase and to an extent you are right.
As I pointed out. In the context of a string to convert to a float, any
upper/lower-case spelling of NaN is accepted.
But, to answer you anyway, I actually use many versions of python as I have
loaded direct versions as well as through Cygwin and the Anaconda
distribution. Should not be relevant as explained.
But when displaying a value that is of that not-quite-type, all versions
have a print definition as all lower case as in 'nan' I think.
But here is a curiosity. The numpy add-on package has a nan that is UNIQUE
so two copies are the same. Read this transcript and see if it might
sometimes even be useful while perhaps confusing the heck out of people who
assume all nans are the same, or is it all nans are different?
>>> floata = float('nan')
>>> floatb = float('nan')
>>> floata, floatb
>>> floata == floatb
>>> floata is floatb
>>> numpya = numpy.nan
>>> numpyb = numpy.nan
>>> numpya, numpyb
>>> numpya == numpyb
>>> numpya is numpyb
From: Python-list <python-list-bounces+avigross=verizon.net at python.org> On
Behalf Of Grant Edwards
Sent: Thursday, February 14, 2019 6:15 PM
To: python-list at python.org
Subject: Re: FW: Why float('Nan') == float('Nan') is False
On 2019-02-14, Avi Gross <avigross at verizon.net> wrote:
> I experimented a bit:
>>>> float("nan ")
>>>> float(" nan")
>>>> float(" nAn")
That's curious. I've never seen "Nan" before. What version of Python are
Grant Edwards grant.b.edwards Yow! NANCY!! Why is
at everything RED?!
More information about the Python-list