[Tutor] Implementation of list comparison operators

Peter Otten __peter__ at web.de
Thu Jan 17 13:39:49 EST 2019


One obscure detail of the implementation of list equality:

In Python an object can be unequal to itself:

>>> class A:
...     def __eq__(self, other): return False
... 
>>> a = A()
>>> a == a
False

However, the list assumes that (a is a) implies a == a, so

>>> [a] == [a]
True




More information about the Tutor mailing list