There is puzzling (at least for me) behavior of Python's set in combination with NaN
s (here live):
>>> float('nan') in {float('nan')} # example 1
False
>>> nan = float('nan') # example 2
>>> nan in {nan}
True
At first, I wrongly assumed,that this is the behavior of the ==
-operator, but this is obviously not the case because both cases yield False
as expected (here live):
>>> float('nan') == float('nan')
False
>>> nan = float('nan')
>>> nan == nan
False
I'm mainly interested in the causes for this behavior. But if there is a way to ensure consistent behavior, that would also be nice to know!