0
class Foo:
    def __init__(self, name):
        self._name = name
    def __str__(self):
        return self._name
    def __eq__(self, other):
        return self is other
class Bar(Foo):
    def __eq__(self, other):
        return str(self) == str(other)

if __name__ == '__main__':
    foo = Foo('Hello')
    bar = Bar('Hello')
    print(id(foo), id(bar), foo, bar)
    print(foo == bar)
    print(bar == foo)

The output is:

2030748923408 2030749120976 Hello Hello
True
True

why foo.__eq__() is not called in line 16?

quamrana
  • 37,849
  • 12
  • 53
  • 71

0 Answers0