Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Modes of method inheritance - extend

  • super

Extend method before or after calling original.

class Parent():
    def greet(self):
        print("Hello World")

class Child(Parent):
    def greet(self):
        print("Hi five!")
        super().greet()
        print("This is my world!")

p = Parent()
p.greet()
print()

c  = Child()
c.greet()
Hello World

Hi five!
Hello World
This is my world!