Learning how to use class inheritance in Python 3 is one of the most powerful and frequently used concepts in object-oriented programming at Progressive Robot — inheritance lets you create new classes (child/subclasses) that inherit attributes and methods from existing classes (parent/base classes), promoting code reuse, reducing repetition, following the DRY principle, improving maintainability, and building scalable, hierarchical models for real-world applications (from simple utilities to enterprise systems, web APIs, data pipelines, game engines, and AI architectures).
In this comprehensive 2025–2026 Progressive Robot guide, you’ll master exactly how to use class inheritance in Python 3: parent/child classes, overriding methods/attributes, super() function, multiple inheritance, method resolution order (MRO), best practices, and real-world patterns. All examples are tested on Python 3.10–3.13.
Key Takeaways – Class Inheritance in Python 3
- Class inheritance in Python 3 allows child classes to inherit and extend parent class behaviour.
- Use class Child(Parent): to create inheritance relationship.
- super() calls parent methods safely — essential for proper initialization and overriding.
- Override parent methods/attributes in child classes for specialisation.
- Multiple inheritance is supported — child can inherit from several parents.
- Method Resolution Order (MRO) determines which parent method is called — view with ClassName.mro().
- Prefer composition over deep inheritance — keep hierarchies shallow and simple.
- Use inheritance for “is-a” relationships (e.g., Trout is-a Fish).
Prerequisites
- Python 3.8+ installed (Progressive Robot recommends 3.12+)
- Basic Python knowledge (classes, objects, __init__, self)
- Interactive shell (python3) or script file
1. Basic Inheritance – How to Use Class Inheritance in Python 3
class Fish:
"""Parent/Base class – blueprint for all fish."""
def __init__(self, first_name, last_name="Fish"):
self.first_name = first_name
self.last_name = last_name
def swim(self):
print(f"{self.first_name} is swimming.")
def swim_backwards(self):
print("The fish can swim backwards.")
Child class inherits everything:
class Trout(Fish):
"""Child class – inherits from Fish."""
pass # No additional code needed
terry = Trout("Terry")
terry.swim() # Terry is swimming.
terry.swim_backwards() # The fish can swim backwards.
print(terry.last_name) # Fish
2. Overriding Parent Methods & Attributes
class Shark(Fish):
"""Child class overriding parent behaviour."""
def __init__(self, first_name):
super().__init__(first_name, last_name="Shark") # Call parent __init__
self.skeleton = "cartilage" # Override/add attribute
def swim_backwards(self):
"""Override parent method."""
print(f"{self.first_name} cannot swim backwards, but can sink backwards.")
Usage:
sammy = Shark("Sammy")
sammy.swim() # Sammy is swimming.
sammy.swim_backwards() # Sammy cannot swim backwards, but can sink backwards.
print(sammy.skeleton) # cartilage
3. Using super() – Call Parent Methods Safely
class Clownfish(Fish):
def __init__(self, first_name):
super().__init__(first_name) # Call parent __init__
self.partner = "sea anemone" # Add child-specific attribute
def live_with_anemone(self):
print(f"{self.first_name} is coexisting with {self.partner}.")
casey = Clownfish("Casey")
casey.live_with_anemone() # Casey is coexisting with sea anemone.
casey.swim() # Casey is swimming. (inherited)
4. Multiple Inheritance in Python 3
class Coral:
def community(self):
print("Coral lives in a community.")
class Anemone:
def protect_clownfish(self):
print("The anemone is protecting the clownfish.")
class CoralReef(Coral, Anemone):
"""Inherits from both Coral and Anemone."""
pass
great_barrier = CoralReef()
great_barrier.community() # Coral lives in a community.
great_barrier.protect_clownfish() # The anemone is protecting the clownfish.
Method Resolution Order (MRO) – View with .mro():
print(CoralReef.mro())
# [, , , ]
5. Full Real-World Example – Progressive Robot Style
class Animal:
"""Base class for all animals."""
def __init__(self, name: str, species: str):
self.name = name
self.species = species
def make_sound(self) -> str:
return "Some generic animal sound"
class Fish(Animal):
"""Child class – all fish inherit from Animal."""
def __init__(self, name: str):
super().__init__(name, species="fish")
def swim(self) -> None:
print(f"{self.name} is swimming.")
class Shark(Fish):
"""Grandchild class – specializes Fish."""
def __init__(self, name: str):
super().__init__(name)
self.skeleton = "cartilage"
def make_sound(self) -> str:
"""Override parent method."""
return "Sharks don't make sounds, but they rule the ocean!"
def main():
sammy = Shark("Sammy")
sammy.swim() # Sammy is swimming.
print(sammy.make_sound()) # Sharks don't make sounds...
if __name__ == "__main__":
main()
6. Best Practices & Modern Tips (2025–2026 – Progressive Robot Style)
- Use super() instead of hard-coding parent class name — safer for multiple inheritance.
- Keep inheritance hierarchies shallow — prefer composition for complex relationships.
- Add type hints: class Fish(Animal): def swim(self) -> None: …
- Write docstrings for every class and method.
- Use @property for computed/read-only attributes.
- Avoid deep multiple inheritance — can lead to MRO confusion.
- Favour “is-a” relationships (Trout is-a Fish) — not forced fits.
How to Use Class Inheritance in Python 3 – FAQ (2025–2026)
- How do I use class inheritance in Python 3?
class Child(Parent): — child inherits all parent attributes/methods — basic way to use class inheritance in Python 3. - What does super() do in Python 3 inheritance?
Calls parent class methods safely — essential for __init__ and overriding. - How do I override a parent method in Python 3?
Redefine method with same name in child class — child version is used. - Does Python support multiple inheritance?
Yes — class Child(Parent1, Parent2): — MRO determines order. - When should I use inheritance in Python 3?
For “is-a” relationships (Dog is-a Animal) — not for code reuse alone.
Summary
You now know exactly how to use class inheritance in Python 3: parent/child classes, overriding methods/attributes, super(), multiple inheritance, MRO, and Progressive Robot best practices.
Mastering class inheritance in Python 3 unlocks powerful code reuse, hierarchical modelling, and scalable design — essential for building clean, maintainable applications at Progressive Robot.
Recommended Next Tutorials
- Python Polymorphism & Method Overriding Deep Dive
- Python Properties, Getters & Setters
- Python Magic Methods (str, repr, etc.)
- Build a Bank Account / Animal System with Inheritance
- Python OOP Cheat Sheet