Created
May 22, 2019 07:43
-
-
Save brydavis/a6e4fbd003dcac0769e81ce9dbb8a901 to your computer and use it in GitHub Desktop.
This file contains hidden or 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(): | |
| x, y = 1, 2 | |
| def __init__(self, a, b): | |
| self.a = a | |
| self.b = b | |
| def total(self): | |
| return self.a + self.b | |
| class B(A): | |
| g = 4 | |
| h = 5 | |
| def __init__(self, a, b): | |
| super().__init__(a, b) | |
| def total(self): | |
| return self.a + self.b + 10 | |
| def multiply(self): | |
| return self.a * self.b | |
| b1 = B(7, 8) | |
| b2 = B(9, 10) | |
| print(b1.g) # 4 | |
| print(b2.g) # 4 | |
| b1.g = 10 | |
| B.g = 30 | |
| print(b1.g) # 10 | |
| print(b2.g) # 30 | |
| print(b1.multiply()) # 56 | |
| print(b1.total()) # 56 | |
| print(b2.multiply()) # 90 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment