Inheritance in Python lets a new class (the child or subclass) reuse and extend the attributes and methods of an existing class (the parent or base class). You write class Child(Parent):, and the child gets everything the parent defines, can override methods and can call the parent's versions with super().
Use inheritance for genuine "is-a" relationships, such as a Dog being an Animal. This guide targets Python 3.12 and later.
super()Dog overrides speak, while Cat inherits it unchanged. Because both are Animal objects, code that works with Animal works with either, which is polymorphism.
super()Use super() to run the parent's implementation, most often in __init__.
If you define __init__ in a child and forget super().__init__(), the parent's setup does not run and attributes will be missing.
| Type | Shape | Example |
|---|---|---|
| Single | One parent | class B(A) |
| Multilevel | Chain of parents | class C(B), class B(A) |
| Hierarchical | Several children, one parent | class B(A), class C(A) |
| Multiple | Several parents | class D(B, C) |
Python supports multiple inheritance. When several parents define the same method, Python searches classes in the method resolution order (MRO), computed with the C3 linearization algorithm. Inspect it with __mro__.
super() follows the MRO, not just the direct parent, so cooperative classes should all call super(). This is how the diamond problem is resolved in Python. Mixins, small classes that add one behaviour, are the most common good use of multiple inheritance.
Use abc.ABC to force subclasses to implement certain methods.
Instantiating Shape() directly raises TypeError, because it has an abstract method. isinstance and issubclass test inheritance relationships at runtime.
Inheritance couples a child tightly to its parent: changes in the parent can break subclasses. Prefer composition ("has-a") when the relationship is not truly "is-a".
A car is not an engine, so it holds one. Keep hierarchies shallow, and for plain interfaces consider typing.Protocol, which supports structural typing without inheritance.
Use issubclass(Child, Parent) for classes or isinstance(obj, Parent) for objects.
Yes. Python resolves method lookup with the MRO, which you can view through ClassName.__mro__ or ClassName.mro().
super() do?It returns a proxy that delegates method calls to the next class in the MRO, letting you reuse parent behaviour without naming the parent class.
Python has no true private members. A name with a leading underscore signals "internal", and a double underscore triggers name mangling, but subclasses can still reach them.
Inheritance lets a class reuse and specialise another class through class Child(Parent). Override methods where behaviour differs, call super() to extend rather than replace, understand the MRO when using multiple parents, use abstract base classes to define contracts, and favour composition when the relationship is not truly "is-a".