I found the following lines in the json/encoder.py
module:
if o != o:
text = 'NaN'
In what situation is an object not equal to itself?
This can happen in the case of floating point numbers that adhere to IEEE 754 standard. See Why is NaN not equal to NaN?
By definition, a value of NaN ("not a number") is unequal to itself.
The question seems to be about NaN, but it's worth mentioning that you can define the comparison method __eq__
in a custom class.
For example you could make it always false:
class NotEqual:
def __eq__(self, other):
return False
n = NotEqual()
print(n == n) # -> False
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With