3) Inheritance Lesson

Introduction to Python Inheritance

3 min to complete · By Martin Breuss

Another base concept of OOP is class inheritance in Python. Through inheritance, you can allow one class to inherit from another class. This means that the child class will automatically have the same methods and attributes as its parent class does:

Best friends - Photo by https://unsplash.com/@itfeelslikefilm Janko Ferlič on Unsplash

You can draw analogies to biological inheritance, which is where the terms originate from. However, this is only a rough analogy, so don't get too stuck with it.

Inheritance Project

In this section of the course, you'll learn about the concept of class inheritance in Python by building a Spice() class that inherits from the Ingredient() class that you built in the previous section.

Lessons

You'll keep building out a code snippet step-by-step over the following lessons. The code that you'll see in the lessons will be slimmed down to the specific concept you're learning about in that lesson. This is to reduce clutter and to help you focus on the topic at hand.

Colorful illustration of a light bulb

Info: The full code will be available in the final recap lesson.

Videos

In the videos, you'll keep building on the same code and extending it. You're encouraged to also keep building on top of the same example and add more functionality.

In the next lesson, you'll start by creating an empty Spice() class that inherits from your Ingredient() class.

Colorful illustration of a light bulb

Additional Resources

Summary: What is Python Class Inheritance

  • Inheritance is a base concept of OOP
  • Inheritance is when one class inherits functionality from another
  • Throughout the lessons in this section, you will build some code step by step
  • The videos will show the code and extend it