Inheritance
Learn how to inherit properties from other classes.
Inheritance is a free Python For Kids lesson on CoddyKit — lesson 3 of 5. You can read the complete lesson below for free — then practise it hands-on in the browser with a built-in code editor and a 24/7 AI tutor. It is part of the Python For Kids learning path, one of 5 lessons in the course, and your progress syncs across the web and the CoddyKit app.
1
Inheritance
Welcome back to the Object-Oriented Programming (OOP) lesson! Today, we'll learn about inheritance in Python, a powerful feature that allows classes to inherit properties and behaviors from other classes.

2
What is Inheritance?
Inheritance is a fundamental concept in OOP that enables a new class (child or subclass) to acquire the attributes and methods of an existing class (parent or superclass). This promotes code reuse and establishes a natural hierarchy between classes.
- Parent Class: The class being inherited from.
- Child Class: The class that inherits from the parent class.
Let's explore how inheritance works in Python!
3
Benefits of Inheritance
Inheritance offers several advantages:
- Code Reusability: Reuse existing code without rewriting it.
- Maintainability: Easier to update and manage code.
- Hierarchy: Establishes a logical relationship between classes.
Now, let's see how to implement inheritance in Python.
4
Defining a Parent Class
First, we'll define a parent class that contains common attributes and methods that can be inherited by child classes.
Example:
# Defines the Animal parent class
class Animal:
def __init__(self, name):
self.name = name # Sets the name of the animal
def speak(self):
print(self.name + " makes a sound.") # Generic speak method
5
Creating a Child Class
Next, we'll create a child class that inherits from the parent class. The child class can have additional attributes and methods or override existing ones.
Example:
# Defines the Dog child class inheriting from Animal
class Dog(Animal):
def speak(self):
print(self.name + " says Woof!") # Overrides the speak method
6
Using the Child Class
Now, let's create an object of the child class and see how it inherits properties and methods from the parent class.
Example:
# Creates an object of the Dog class
my_dog = Dog("Buddy")
# Calls the speak method
my_dog.speak() # Output: Buddy says Woof!
7
Multiple Inheritance
Python allows a class to inherit from multiple parent classes, combining their attributes and methods. This is known as multiple inheritance.
- Parent Classes: All classes from which properties and methods are inherited.
Example:
# Defines the Flyer parent class
class Flyer:
def fly(self):
print("I can fly!")
# Defines the Swimmer parent class
class Swimmer:
def swim(self):
print("I can swim!")
# Defines the Duck child class inheriting from both Flyer and Swimmer
class Duck(Flyer, Swimmer):
def speak(self):
print("Quack!")
8
Using Multiple Inheritance
Let's create an object of the Duck class and see how it inherits methods from both parent classes.
Example:
# Creates an object of the Duck class
donald = Duck()
# Calls methods inherited from both parent classes
donald.fly() # Output: I can fly!
donald.swim() # Output: I can swim!
# Calls the speak method defined in the Duck class
donald.speak() # Output: Quack!
9
# Defines the Vehicle parent class
class Vehicle:
def __init__(self, brand):
self.brand = brand # Sets the brand of the vehicle
def drive(self):
print(self.brand + " is driving.")
# Defines the Car child class inheriting from Vehicle
class Car(Vehicle):
def drive(self):
print(self.brand + " is driving a car.")
# Creates an object of the Car class
my_car = Car("Toyota")
# Calls the drive method
my_car.drive()
10
Great Job!
You've learned how to use inheritance in Python to create child classes that inherit properties and methods from parent classes. Inheritance helps you build organized and reusable code, making your programs more efficient and easier to manage. Keep practicing by creating your own classes and exploring different inheritance scenarios!

Frequently asked questions
Is the “Inheritance” lesson free?
Yes — the full text of “Inheritance” is free to read here on the web, and the Python For Kids course includes 5 lessons in total. To practise it interactively (a built-in code editor and a 24/7 AI tutor) and unlock the rest of the Python For Kids course, upgrade to CoddyKit PRO.
What will I learn in “Inheritance”?
Learn how to inherit properties from other classes. You practise Python For Kids with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.
Do I need any experience to start Python For Kids?
No prior experience is required. Python For Kids on CoddyKit is structured for beginners through advanced learners; this is — lesson 3 of 5, so you can start here or from the beginning and move at your own pace.
How long does the “Inheritance” lesson take?
Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.
Can I write and run code in this Python For Kids lesson?
Yes. Every Python For Kids lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.