[Tutor] Implementation of list comparison operators

David Rock david at graniteweb.com
Thu Jan 17 14:04:51 EST 2019


> On Jan 17, 2019, at 12:39, Peter Otten <__peter__ at web.de> wrote:
> 
> 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

Isn’t this a bit artificial, though?  The reason this is False is because you explicitly tell it to return False when using equality.  That’s not the same thing as using __eq__ without overriding it’s behavior internally.


— 
David Rock
david at graniteweb.com






More information about the Tutor mailing list