inheritance
In object-oriented programming (OOP), inheritance allows you to create a new class by inheriting features from an existing one. You can define a class that inherits data (attributes) and behavior (methods) from another class, known as the base class, superclass, or parent class.
This mechanism promotes code reuse and helps you create a hierarchical class structure that reflects real-world relationships. By using inheritance, you can override or extend the functionality of the parent class to tailor the behavior of the derived or child class to meet specific requirements.
Example
Here’s an example of inheritance in Python:
class Vehicle:
def __init__(self, brand, model):
self.brand = brand
self.model = model
def start_engine(self):
print(f"The {self.brand} {self.model}'s engine is starting!")
class SelfDrivingCar(Vehicle):
def self_drive(self):
print("Self-driving through the road!")
# Usage
car = SelfDrivingCar("Waymo", "One")
car.start_engine() # Output: The Waymo One's engine is starting!
car.self_drive() # Output: Self-driving through the road!
In this example, the SelfDrivingCar class inherits from the Vehicle class. Apart from .brand, .model and .start_engine(), which are inherited members, the class implements the .self_drive() method to provide extended functionality.
Related Resources
Course
Inheritance and Internals: Object-Oriented Programming in Python
In this video course, you'll learn about the various types of inheritance that you can use to write object-oriented code in Python. These include class inheritance, multilevel inheritance, and multiple inheritance, along with special methods and abstract base classes.
For additional information on related topics, take a look at the following resources:
- Supercharge Your Classes With Python super() (Tutorial)
- Inheritance and Composition: A Python OOP Guide (Tutorial)
- Object-Oriented Programming (OOP) in Python (Tutorial)
- Python Classes: The Power of Object-Oriented Programming (Tutorial)
- Supercharge Your Classes With Python super() (Course)
- Supercharge Your Classes With Python super() (Quiz)
- Inheritance and Composition: A Python OOP Guide (Course)
- Inheritance and Composition: A Python OOP Guide (Quiz)
- A Conceptual Primer on OOP in Python (Course)
- Intro to Object-Oriented Programming (OOP) in Python (Course)
- Object-Oriented Programming (OOP) in Python (Quiz)
- Class Concepts: Object-Oriented Programming in Python (Course)
- Python Classes - The Power of Object-Oriented Programming (Quiz)
Have a question about this? Mentor AI can show you examples, compare related terms, and point you to tutorials.
By Leodanis Pozo Ramos • Updated Sept. 10, 2026