1

I read Why does float('nan') == float('nan') return False? and accept that float('nan) != float('nan'). I modified my code to successfully use math.isnan().

But if float('nan') cannot be found in lists, why can math.nan be found in lists?

$ python
Python 3.6.4 |Anaconda, Inc.| (default, Jan 16 2018, 18:10:19)
[GCC 7.2.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import math
>>> math.nan in [ 1.0, 2.0, float('nan'), 5.0 ]
False
>>> float('nan') in [ 1.0, 2.0, float('nan'), 5.0 ]
False
>>> math.nan in [ 1.0, 2.0, math.nan, 5.0 ]
True
Kevin M. Mansour
  • 2,915
  • 6
  • 18
  • 35

0 Answers0