*Two Python objects are π’πππ§ππ’πππ₯ if they are located at the same memory address. Or, more precisely, the ππ() function returns the same value for both objects.
So whatβs happening here?
Python checks two conditions when determining if an object is a member of a collection (i.e., list, set, dict keys):
1οΈβ£ Is the object identical to one of the objects in the collection?
2οΈβ£ Is the object equal (using ==) to an object in the collection?
If either one of those conditions is true, then the object is a member of the collection.
But neither of those conditions are ever true for πππππ(βπππβ)!
That said, since πππππ(βπππβ) is a floating point value β and thus immutable β thereβs no problem using πππππ(βπππβ) in a set or as a dictionary key.
I know, it can be kind of confusing.
Letβs add another NaN to the mix.
πππππ(βπππβ) isnβt the only way to make a NaN object in Python.
No, Iβm not talking about πππππ’.πππ.
Who knows whatβs going on here? Whatβs the difference between ππππ.πππ and πππππ(βπππβ)?
100 internet points to the first person with the right answer!
And if you want even more NaN craziness, check out the discussion thread from the Python issue tracker that led to the inclusion of ππππ.πππ.
For instance, did you know that there are π΄πͺπ¨π―π¦π₯ NaNs? π€―