Suppose I have the following program:
class A(object):
def __eq__(self, other):
return True
a0 = A()
a1 = A()
print a0 != a1
If you run it with Python the output is True. My question is
__ne__ method is not implemented, does Python fall on a default one?__eq__ and then negate the result?From the docs:
There are no implied relationships among the comparison operators. The truth of
x==ydoes not imply thatx!=yis false. Accordingly, when defining__eq__(), one should also define__ne__()so that the operators will behave as expected.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With