Module lessons (2/4)
Inheritance
Subclasses, super(), method overrides, isinstance, and foundational C3 MRO lookup.
What you'll learn in this lesson
- Create specialized subclasses with
class Child(Parent):by reusing methods and shared state. - Safely delegate initialization to the parent with
super().__init__(...). - Override methods while maintaining polymorphic compatibility and test types with
isinstance()andissubclass(). - Read MRO (C3 linearization) resolution order in multiple inheritance.
Overview
Inheritance models an "is-a" (is-a) relationship: a subclass inherits the superclass's methods and attributes, can add new ones, and can redefine (override) existing ones to specialize the behavior.
When you search for a method on a subclass, Python follows a precise ordered list called MRO (Method Resolution Order): it scrolls through the hierarchy from left to right without ever visiting the same shared class twice (C3 linearization algorithm).
Sections covered in this lesson
- 11. Subclassing, overriding and polymorphism
- 22. Extend the parent with
super() - 33. Test the hierarchy with
isinstanceandissubclass - 44. Multiple inheritance, mixins and
.mro() - 5Check for understanding
- 6Test yourself
Unlock "Inheritance" and the full Python Course curriculum
Subclasses, super(), method overrides, isinstance, and foundational C3 MRO lookup.
Unlock all 5 hands-on exercises in this lesson plus every advanced WebAssembly module with automated checks.
- Instant access to all advanced modules in Python Course plus 17 more courses
- Hands-on browser exercises with automated test suites and solutions
- 14-day money-back guarantee processed via Paddle.com
14-day guarantee · Cancel anytimeModule 1, all 18 interactive games, and cheatsheets are always free.