0Pricing
Python Academy · Lesson

Single Inheritance

Create child classes that inherit attributes and methods from a parent.

Introduction

Inheritance lets a child class reuse and extend the behavior of a parent class without duplicating code.

Defining a Child Class

class Dog(Animal): inherits everything from Animal. The child class can add new methods or override existing ones.
class Animal:
    def __init__(self, name): self.name = name
    def speak(self): return '...'
class Dog(Animal):
    def speak(self): return 'Woof'
d = Dog('Rex')
print(d.name, d.speak())

All lessons in this course

  1. Single Inheritance
  2. Method Overriding and super()
  3. Multiple Inheritance and MRO
  4. Polymorphism and Duck Typing
← Back to Python Academy