How can I check for NaN values?

后端 未结 17 2228
盖世英雄少女心
盖世英雄少女心 2020-11-22 05:02

float(\'nan\') results in Nan (not a number). But how do I check for it? Should be very easy, but I cannot find it.

17条回答
  •  深忆病人
    2020-11-22 05:48

    With python < 2.6 I ended up with

    def isNaN(x):
        return str(float(x)).lower() == 'nan'
    

    This works for me with python 2.5.1 on a Solaris 5.9 box and with python 2.6.5 on Ubuntu 10

提交回复
热议问题