Python 2.7.3 (default, Aug 1 2012, 05:14:39)
[GCC 4.6.3] on linux2
Type \"help\", \"copyright\", \"credits\" or \"license\" for more information.
>>> x =
Not A Number (NaN) is unequal with anything. To detect it, use math.isnan. And an object like this is quite easy to define:
class A(object):
def __eq__(self, other):
return False
def __ne__(self, other):
return True
The reason why this is is quite simple. CPython follows the IEEE 754 standard for floating point math. NaN is a floating point value for which IEEE 754 dictates that it is not equal to any other floating point value.