by Pinus · 1y ago · 0 comments
>>> nan=float('nan')
>>> a=[nan]
>>> nan in a
True
>>> any(nan==x for x in a)
False
(Because the `in` operator assumes that identity implies equality...)Well, more precisely, this is how the operator behaves for most built in collections; other types can define how it behaves for them by implementing a __contains__() method with the desired semantics.
[0] https://docs.python.org/3/reference/expressions.html#members...