githubEdit

Inheritance

Inheritance lets a class reuse and extend another class.

Example

class Vehicle:
    def move(self):
        print("Moving")

class Car(Vehicle):
    def honk(self):
        print("Beep")

car = Car()
car.move()
car.honk()

super()

class Animal:
    def __init__(self, name):
        self.name = name

class Dog(Animal):
    def __init__(self, name, breed):
        super().__init__(name)
        self.breed = breed

Next | Previous

Last updated