Created
March 31, 2022 11:03
-
-
Save axil/607a4a388a4704a985013f8f651b18ab to your computer and use it in GitHub Desktop.
inheritance1
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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