python - Does __ne__ use an overridden __eq__? -
suppose have following program:
class a(object): def __eq__(self, other): return true a0 = a() a1 = a() print a0 != a1
if run python output true
. question
- the
__ne__
method not implemented, python fall on default one? - if python fall on default method determine whether 2 objects equal or not, shouldn't call
__eq__
, negate result?
from the docs:
there no implied relationships among comparison operators. truth of
x==y
not implyx!=y
false. accordingly, when defining__eq__()
, 1 should define__ne__()
operators behave expected.
Comments
Post a Comment