Last modified: Dec 01, 2026

Single Inheritance in Python Example

Single inheritance is the simplest form of inheritance in Python. One child class inherits from one parent class. That is the whole idea.

This pattern keeps your code clean. The child class reuses the parent's attributes and methods. You write less code and avoid repetition.

In this article, we will walk through a full example. We will also cover method overriding, super(), and common mistakes. By the end, you will know exactly how single inheritance works.

What Is Single Inheritance?

Inheritance lets a class build on another class. The original class is the parent or base class. The new class is the child or derived class.

Single inheritance means there is exactly one parent and one child. The child gets everything the parent has, unless it overrides it.

Python uses a simple syntax for this. You put the parent class name in parentheses after the child class name.


class Parent:
    pass

class Child(Parent):
    pass

That one line, class Child(Parent), creates the inheritance link. It is easy to miss how much this does. The child now has access to all parent methods and attributes.

A Basic Single Inheritance Example

Let's start with a real example. We will model an animal and a dog.


class Animal:
    def __init__(self, name):
        self.name = name  # store the animal name

    def speak(self):
        return f"{self.name} makes a sound."

class Dog(Animal):
    def fetch(self):
        return f"{self.name} fetches the ball."

# Create a dog object
d = Dog("Rex")

print(d.speak())   # inherited method
print(d.fetch())   # child method

Rex makes a sound.
Rex fetches the ball.

Notice that Dog never defines an __init__ method. It still works. The child automatically uses the parent's constructor.

The speak() method is inherited. The fetch() method belongs only to the child. This mix of shared and unique behavior is the core of inheritance.

If you are new to classes, start with these Python class basics for beginners before going deeper.

How the Child Class Reuses the Parent

When Python creates a Dog object, it looks for methods in a specific order. First it checks the child class. Then it checks the parent class.

This lookup order is called the method resolution order. In single inheritance, the order is simple: child first, then parent.

So when you call d.speak(), Python does not find it in Dog. It moves up to Animal and runs it there.

The child is not a copy of the parent. It is a separate class that points to the parent. This matters when you change the parent later.

Overriding Methods in the Child

Sometimes the parent behavior is not right for the child. You can override a method by defining it again in the child class.


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

    def speak(self):
        return f"{self.name} makes a sound."

class Dog(Animal):
    def speak(self):
        return f"{self.name} barks loudly."

d = Dog("Rex")
print(d.speak())

Rex barks loudly.

The child's version wins. Python finds speak() in Dog and stops there.

Overriding is powerful, but use it with care. If a method name means one thing in the parent, keep that meaning in the child. Otherwise your code becomes confusing.

This is one of the key ideas covered in inheritance in Python explained in more depth.

Using super() to Call the Parent

Often you want the child to add its own setup but still run the parent's setup. That is where super() comes in.


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

class Dog(Animal):
    def __init__(self, name, breed):
        super().__init__(name)  # run the parent constructor
        self.breed = breed      # add a child-only attribute

    def info(self):
        return f"{self.name} is a {self.breed}."

d = Dog("Rex", "Labrador")
print(d.info())

Rex is a Labrador.

The call super().__init__(name) runs the parent constructor. Then the child adds its own attribute.

Without super(), you would have to repeat the parent's code. That defeats the purpose of inheritance.

Always call super() first in __init__ unless you have a clear reason not to. It keeps the object in a valid state.

Adding New Attributes and Methods

A child class can add anything it needs. New attributes, new methods, new behavior. The parent does not change.


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

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

    def birthday(self):
        self.age += 1  # increase the age by one
        return f"{self.name} is now {self.age} years old."

d = Dog("Rex", 3)
print(d.birthday())

Rex is now 4 years old.

This keeps related logic together. The Dog class handles dog-specific things. The Animal class handles shared things.

This is the same design you will see in many real projects. If you want to see how attributes are structured, read this guide on Python class methods and attributes.

Checking Inheritance with isinstance and issubclass

Python gives you built-in tools to test relationships. Use isinstance() to check an object. Use issubclass() to check a class.


class Animal:
    pass

class Dog(Animal):
    pass

d = Dog()

print(isinstance(d, Dog))      # True
print(isinstance(d, Animal))   # True, because Dog is an Animal
print(issubclass(Dog, Animal)) # True

True
True
True

The second line is important. A Dog object counts as an Animal too. That is the whole point of inheritance.

These checks are useful in conditional logic. They let you handle objects by their family, not just their exact class.

Common Mistakes with Single Inheritance

Forgetting to call super() is the most common error. The child's __init__ runs, but the parent's does not. Attributes go missing.


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

class Dog(Animal):
    def __init__(self, breed):
        self.breed = breed  # parent __init__ never runs

d = Dog("Labrador")
print(d.name)  # this will fail

AttributeError: 'Dog' object has no attribute 'name'

The fix is simple. Call super().__init__(name) inside the child constructor.

Overriding too much is another trap. If the child replaces every parent method, inheritance adds no value. Use it to share real logic.

Deep chains are also risky. Single inheritance is one level. If you keep chaining child to child, the code gets hard to follow. Keep it shallow when you can.

If you want a broader view of the topic, see the different types of Python inheritance and when each one fits.

A Complete Practical Example

Let's put everything together in one clean program.


class Employee:
    def __init__(self, name, salary):
        self.name = name
        self.salary = salary

    def details(self):
        return f"{self.name} earns {self.salary}."

class Manager(Employee):
    def __init__(self, name, salary, team_size):
        super().__init__(name, salary)
        self.team_size = team_size

    def details(self):
        base = super().details()  # reuse parent logic
        return f"{base} Manages {self.team_size} people."

m = Manager("Ana", 75000, 5)
print(m.details())

Ana earns 75000. Manages 5 people.

This example shows the full pattern. The child reuses the parent constructor. It overrides the method. It also calls the parent version inside the override.

That last part is a great habit. You keep the shared logic in one place and extend it in the child.

When to Use Single Inheritance

Use single inheritance when two classes have a clear "is a" relationship. A manager is an employee. A dog is an animal.

Avoid it when the relationship is "has a". A car has an engine. That is composition, not inheritance.

Also avoid it when the child only needs one method. A simple function or a shared utility may be enough.

For a quick refresher on the whole concept, try Python inheritance made simple. It pairs well with this article.

Conclusion

Single inheritance in Python is easy to learn and easy to use. One parent, one child, and a clean way to share code.

You now know the syntax. You can create a child class, inherit methods, override them, and call the parent with super().

You also know the common mistakes. Forgetting super() and over-overriding are the big ones. Watch for them in your own code.

Start small. Build a parent class with shared logic. Add a child class with one new feature. Then test it with real output.

That practice will make inheritance feel natural fast. And it will keep your Python projects clean and readable.