Modes of method inheritance - extend


Extend method before or after calling original.


examples/oop/inheritance/extend.py
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!