Matthew Muller
Matthew Muller

Reputation: 333

Docs state that x==y does not imply x!=y, is this true?

As question states, python docs state a rather contradictory line. The line in question can be found on this page.

The line in question states, rather bluntly:

"There are no implied relationships among the comparison operators. The truth of x==y does not imply that x!=y is false."

Is there a statement in Python that fulfills this claim? Or is it only limited to convoluted gotcha code.

Upvotes: 1

Views: 77

Answers (1)

Ryan Stout
Ryan Stout

Reputation: 1028

An example where both == and != are True is the following

  class MyClass:
    def __init__(self):
        pass
    def __eq__(self, other):
        return True
    def __ne__(self, other):
        return True

  b1 = MyClass()
  b2 = MyClass()
  print b1 == b2
  print b1 != b2

both lines above will print True

Upvotes: 4

Related Questions