1. Concept library
  2. Python Foundations
  3. Module 9: Classes and objects

Concept

Inheritance

A subclass reuses and extends a parent class: it inherits the methods, overrides the ones that differ, and calls super() to reuse the parent's version.

What a session covers

The tutor works through these with you, in conversation and code. A session ends when you have shown them, not when a video does.

  1. Explain what a subclass inherits and how it overrides a method
  2. Write a subclass that extends a parent and calls super().__init__()
  3. Spot the AttributeError caused by skipping the parent's __init__

In practice

A few lines that show Inheritance doing its job.

Python
class Shape:
    def describe(self):
        return f"{type(self).__name__} with area {self.area():.1f}"

class Square(Shape):
    def __init__(self, side):
        self.side = side

    def area(self):
        return self.side ** 2

print(Square(3).describe())    # Square with area 9.0

The common mistake

Watch for

Overriding __init__ without calling super().__init__(), so the attributes the parent sets up are missing and the inherited methods fail with AttributeError.

What to know first

Your roadmap puts these before Inheritance, unless you already know them.

How it stays learned

Once a session shows you understand Inheritance, it comes back for review. Each review takes a minute and tells the memory model how well you still know it.

  1. Day 3First recall, while it is fresh
  2. Day 7Second, a week on
  3. Day 18Last, when it has settled
Previous in the module← Methods and self