Skip to content

Instantly share code, notes, and snippets.

@axil
Created March 31, 2022 11:03
Show Gist options
  • Save axil/607a4a388a4704a985013f8f651b18ab to your computer and use it in GitHub Desktop.
Save axil/607a4a388a4704a985013f8f651b18ab to your computer and use it in GitHub Desktop.
inheritance1
class A:
def __init__(self, v):
self.v = v
def __lt__(self, other):
print(f'A: {self.v} < {other.v} ?')
return self.v < other.v
class B(A):
def __lt__(self, other):
print(f'B: {self.v} < {other.v} ?')
return self.v < other.v
>>> B(5) < A(7)
B: 5 < 7 ? < -- right
True
>>> A(5) < B(7)
A: 5 < 7 ? < -- wrong!
True
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment