test for nan

Skip Montanaro skip at pobox.com
Wed Mar 31 12:30:34 EST 2004


    John> Is there a better way to test for NaN than

    John>    str(p1)=='nan'

    John> where p1 is a float?

Saw this in the list archives earlier today:

    >>> inf = float("1e9999")
    >>> inf
    Inf
    >>> nan = inf-inf
    >>> nan
    NaN
    >>> p1 = 5.0
    >>> p1 == nan
    False

Skip




More information about the Python-list mailing list