0Pricing
Python Academy · Lesson

Single Inheritance

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

Single Inheritance is a free Python Academy lesson on CoddyKit — lesson 1 of 4. 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 Academy learning path, one of 4 lessons in the course, and your progress syncs across the web and the CoddyKit app.

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())

Calling super().__init__

super().__init__(args) calls the parent's __init__. Always call it in the child when the parent has setup logic.
class Animal:
    def __init__(self, name): self.name = name
class Dog(Animal):
    def __init__(self, name, breed):
        super().__init__(name)
        self.breed = breed
d = Dog('Rex', 'Labrador')
print(d.name, d.breed)

Inheriting Methods

The child inherits all methods of the parent. If you don't override them, they work unchanged.
class Vehicle:
    def start(self): return 'starting'
class Car(Vehicle):
    pass
print(Car().start())

Overriding Methods

Define the same method name in the child to replace the parent's version. The child version is called.
class Shape:
    def area(self): return 0
class Square(Shape):
    def __init__(self, s): self.s = s
    def area(self): return self.s**2
print(Square(4).area())

Extending Parent Behavior

Call super().method() inside the override to run the parent version first, then add more.
class Animal:
    def describe(self): return 'I am an animal'
class Dog(Animal):
    def describe(self): return super().describe() + ' and a dog'
print(Dog().describe())

isinstance() and issubclass()

isinstance(obj, Parent) returns True for child instances too. issubclass(Child, Parent) checks the class hierarchy.
class Animal: pass
class Dog(Animal): pass
d = Dog()
print(isinstance(d, Animal))
print(issubclass(Dog, Animal))

Child Adds New Methods

The child can define entirely new methods that the parent doesn't have.
class Animal:
    def __init__(self, name): self.name = name
class Dog(Animal):
    def fetch(self): return f'{self.name} fetches!'
print(Dog('Rex').fetch())

Protected Attributes

_name convention signals 'don't access from outside the class'. Subclasses CAN use them.
class Animal:
    def __init__(self, name): self._name = name
    def name(self): return self._name
class Dog(Animal):
    def bark(self): return f'{self._name} barks'
print(Dog('Rex').bark())

Abstract Base Classes

from abc import ABC, abstractmethod forces subclasses to implement methods.
from abc import ABC, abstractmethod
class Shape(ABC):
    @abstractmethod
    def area(self): pass
class Circle(Shape):
    def __init__(self, r): self.r = r
    def area(self):
        import math
        return math.pi * self.r**2
print(Circle(3).area())

__bases__ and __mro__

Dog.__bases__ shows direct parents. Dog.__mro__ shows the full method resolution order.
class A: pass
class B(A): pass
class C(B): pass
print(C.__mro__)

Quick Check

What does super().__init__() do in a child class?

Recap

Inheritance: class Child(Parent). super() accesses parent. Override methods to change behavior. isinstance() checks hierarchy. ABC enforces abstract contracts.

Keep Going

Excellent progress! Keep going to master the next concept.

Frequently asked questions

Is the “Single Inheritance” lesson free?

Yes — the full text of “Single Inheritance” is free to read here on the web, and the Python Academy course includes 4 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 Academy course, upgrade to CoddyKit PRO.

What will I learn in “Single Inheritance”?

Create child classes that inherit attributes and methods from a parent. You practise Python Academy 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 Academy?

No prior experience is required. Python Academy on CoddyKit is structured for beginners through advanced learners; this is — lesson 1 of 4, so you can start here or from the beginning and move at your own pace.

How long does the “Single 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 Academy lesson?

Yes. Every Python Academy 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.

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