- super
Inheritance
examples/oop/inheritance/shapes.py
class Point: def __init__(self, x, y): print('__init__ of Point') self.x = x self.y = y def move(self, dx, dy): self.x += dx self.y += dy class Circle(Point): def __init__(self, x, y, r): print('__init__ of Circle') super().__init__(x, y) self.r = r def area(self): return self.r * self.r * 3.14
examples/oop/inheritance/circle.py
import shapes c = shapes.Circle(2, 3, 10) # __init__ of Circle # __init__ of Point print(c) # <shapes.Circle instance at 0x7fb58c31ccb0> print(c.x) # 2 print(c.y) # 3 print(c.r) # 10 c.move(4, 5) print(c.x) # 6 print(c.y) # 8 print(c.area()) # 314.0