Inheritance

Defining a class that builds on another, reusing its attributes and methods.

Inheritance lets a child class reuse the attributes and methods of a parent class: class Dog(Animal):. The child can add new behaviour or override a method to replace the parent's version.

Call super() to reuse the parent's version from inside the child. Reach for inheritance only when the child genuinely is a kind of the parent.

Example
class Animal:
    def speak(self):
        return "..."

class Dog(Animal):             # Dog inherits from Animal
    def speak(self):           # override the parent method
        return "Woof"

print(Dog().speak())
print(isinstance(Dog(), Animal))
Output
Woof
True

Where this shows up in real Python

Inheritance shares behaviour across related classes — the pattern behind framework base classes for forms, models, and views you customise.

Commonly used Inheritance tools

  • class Car(Vehicle) — Car inherits everything from Vehicle
  • super().__init__(...) — run the parent’s setup too
  • def describe(self) — override a method to specialise it

Official documentation: Python Tutorial: Inheritance

Related terms