The NaNny State

Ben Finney ben+python at
Mon Feb 18 17:07:44 EST 2019

"Avi Gross" <avigross at> writes:

> It is about the recent discussion about the concept and word "nan" as used
> in python and elsewhere. As noted, the correct spelling in python is all
> lower case as in "nan" with a minor exception that creating a nan using
> float(string) allows any combination of cases such as string="nAN".

Who says that the “correct spelling in python is all lower case "nan"”?

The text representation of a Python ‘float’ NaN object is 'nan'. That is
what the object emits as its text representation; it is not the same
thing as "the correct spelling".

As you note, the ‘float’ type accepts several spellings as input to
create a NaN object, all of them correct spelling.

Similarly, I can spell the number one thousand ‘1000.0’, ‘1.0e+3’
‘1.000e+3’, ‘1000.00000’, and so on. Those are all correct (and, as it
happens, they all result in equal ‘float’ values).

The resulting object will, when I interrogate it, represent itself *by
default* as ‘1000.0’; Python is not showing *the* correct spelling, just
one possible correct spelling.

 \     “I wrote a song, but I can't read music so I don't know what it |
  `\    is. Every once in a while I'll be listening to the radio and I |
_o__)        say, ‘I think I might have written that.’” —Steven Wright |
Ben Finney

More information about the Python-list mailing list