The set is a set of hashables . Although the 1 is True statement is False, the statement 1 == True is True. Because of this, they have the same hash value and cannot exist separately in the set, and you cannot keep them in the set
EDIT To make this explicit, as jme noted, this is because BOTHs are true - they are equal (for __eq__ ) and they have the same hash value (for __hash__ ).
In an ideal world, equal objects will also have the same hash value, and, fortunately, this is true for built-in types.
mehtunguh
source share