Python Day #16: Learn Python Inheritance the Right Way in Minutes
Learn how Python inheritance works with examples. Master OOP faster, reuse code smarter, and take your programming skills to the next level—fast.
You’re here because you’ve been working hard and solidifying your understanding of Object-oriented programming, you’ve been expanding your Python skills.
We’ve already hit on some of the key points in gaining a deep understanding on this larger than life programming topic. You’ve been introduced to classes and objects through interactive coding.
Last lesson we focused on the first pillar of object-oriented programming which is Encapsulation. Here you learned how to actually build out your own classes while creating properties and methods of your own.
If you’ve been following along with our Roadmap to Python Series, you’ve already learned so much, so well done! I’ve made sure that this entire series builds to give you the real skills and logical thinking skills you need to form a solid foundation.
This lesson will focus on the second pillar of OOP, we will expand on the idea of encapsulation but dive deeper into this concept with the pillar known as Inheritance.
Every week you’ll be introduced to a new topic in Python, think of this as a mini starter course to get you going and allow you to have a structured roadmap that actually builds to create you a solid foundation in Python. Join us today!
What comes to mind when I say “Inheritance”? Do you think about inheriting money? Or maybe you think about inheriting traits from your parents. These concepts will apply to this topic here today.
The idea of inheritance in programming is where we can program out a base class, then we can give this base class to children. These children are known as derived classes. We don’t need to program everything out from scratch again.
Over the last 8+ years I’ve been teaching full-time around the world which has given me the unique opportunity to work with over 1,500+ students. The last four years I’ve been teaching Python full-time. Breaking down complex topics, step by step.
I’ve spent this time curating a structured learning path that ensures my students have the greatest chance of success and don’t just learn but actually master Python as well as their logical thinking and problem solving.
One point I should note is, spend time digesting these when I write them, after six weeks most of my posts are automatically put behind a paywall.
If you haven’t subscribed to my premium content yet, you should definitely check it out. You unlock exclusive access to all of these articles and all the code that comes with them, so you can follow along!
Plus, you’ll get access to so much more, like monthly Python projects, in-depth weekly articles, the '3 Randoms' series, and my complete archive!
I spend a lot of my week on these articles, so if you find it valuable, consider joining premium. It really helps me keep going and lets me know you’re getting something out of my work!
Thank you for allowing me to do work that I find meaningful. This is my full-time job so I hope you will support my work by joining as a premium reader today.
If you’re already a premium reader, thank you from the bottom of my heart! You can leave feedback and recommend topics and projects at the bottom of all my articles.
👉 I genuinely hope you get value from these articles, if you do, please help me out, leave it a ❤️, and share it with others who would enjoy this. Thank you so much!
P.S - I’ve gotten a lot of feedback and have listened to you guys. I have some big changes coming to my Masterclass real soon. Expect some promotional content next week in addition to my regular work! 👀
Recap of Encapsulation in OOP
Let me refresh your mind with the topic of last lesson as this is key to understand the next three pillars we will build on so you have a deeper understanding of this topic.
Encapsulation in Object-Oriented Programming (OOP) is the core concept that involves grouping data (attributes/properties) and the methods (functions) that control the data within a single unit. We can call this “unit” a Class.
This whole idea aims to restrict direct access to the internal state of an object and expose only a controlled interface for interaction. Really that was a whole lot of jargon.
How I want you to view encapsulation is similar to a folder. In a folder we store certain items that relate to each other for instance. Well, in encapsulation we basically make what’s called a class.
This class can store variables which relate to something that uses the class. It can also hold functions that only objects defined from the class can use. This allows us to really expand on our programming and program for a unique scenario that we can reuse.
👉 I genuinely hope you get value from these articles, if you do, please help me out, leave it a ❤️, and share it with others who would enjoy this. Thank you so much!
Inheritance in Object-Oriented Programming
Great, you’re now all caught up to where we can pick up with this lesson. Now the idea of inheritance is we build a base class, this class can be rather broad.
Then we can get more specific with the way we want our programs to act and function so we can define a child class which can have attributes and actions of its own while maintaining the methods inherited from the parent class.
Think of it like this: If I ask you, “Do you have a computer?”, That is a yes or no answer. Computer could be seen as the parent class, then we could build out a class for Windows, Mac, and Linux.
These three would be the child classes. They could inherit many attributes and actions from the parent class but then we could give them their own unique properties and actions as well as they function slightly different.
Now there is something crucial that you want to ask yourself as you begin to build out children to the parent class. Does the child class need new properties (attributes)?
If the answer is yes, then we need to initialize the parent class in the child. If the answer is no, then there is no real need to initialize the parent class.
Also my terminology here isn’t actually correct. For learning, I prefer to call the two types of classes: parent and child. This is easier to wrap our heads around.
In reality the parent class is known as the superclass and the child class is known as the derived class. Keep this in mind as you continue working and reading up on this topic.
👉 I genuinely hope you get value from these articles, if you do, please help me out, leave it a ❤️, and share it with others who would enjoy this. Thank you so much!
Ready to Go From Zero to Confident in 90 Days?
Most people get stuck before they even start…
They waste hours Googling, watching random YouTube videos, and never actually finish a project. But that doesn’t have to be you.
I’ve built The Python Masterclass to take you from “I don’t know where to start” to “I can build real-world Python projects” — in less than 90 days.
👉 I’m giving you my exact system that’s been proven and tested by over 1,500 students over the last 4+ years!
Here’s what you’ll get when you join today:
✅ All Course Videos — Learn Python without wasting time on scattered tutorials
✅ Python Templates & eBooks — Pre-built scripts, guides, and checklists
✅ How to Build a Portfolio - Mini Course — Learn the 5 step process ✅ Bi-monthly Live Q&A Calls (Pro/Elite) — Get answers in real time
✅ Portfolio/CV Reviews (Pro/Elite) — Tailored feedback to help you land work
✅ Personal Onboarding, Fast Support, & Custom Feedback (Elite) — I’ll personally guide to keep you moving
✅ Access The Nerd Nook premium FREE (Pro/Elite) — Stay ahead with insider tips
My masterclass is designed so you see your first win in just 7 days — you’ll build your first working Python scripts in week one and finish your first full project in your first month.
With just 30–45 minutes a day, you’ll be on your way to becoming a confident Python developer.
👉 Ready to get started?
P.S. — The sooner you start, the sooner you’ll have projects you can actually show to employers or clients. Imagine where you’ll be 90 days from now if you start today.
The Second Pillar of OOP in Action
Now I want to showcase to you all how inheritance can be done in our code. We will look at both routes to inheritance and I’ll touch on how it’s done and why.
Below I built out a parent class, Language
. This parent does not have __init__
as there is no outside information needed for this example, so we do not need any properties or an initialization.
There is just a single method, ask
. When this method is called it simply returns in english “How are you?”. This is the parent class in this situation, now below the parent class is where I defined a child class, which I called Vietnamese
.
You can see in the parentheses after Vietnamese
I have put the parent class, Language
. This is the most basic form of inheritance, here I am inheriting everything from the parent class in one go.
This child class has a unique method of its own, this method is ask_in_vn
which will ask the same question, but this time in Vietnamese. While the child class has access to both methods: ask
and ask_in_vn
. The parent class does not have access to any of the components in the child.
When I make my object lang
, I make sure that it is an object of the Vietnamese
class. Then I can use this object on both methods as it can access its own methods as well as any methods in its parent class too!
👉 I genuinely hope you get value from these articles, if you do, please help me out, leave it a ❤️, and share it with others who would enjoy this. Thank you so much!
That was a simple start to all this. Now we can look at the second path to inheritance. this is the path we take when we have properties. Now if the parent class has properties, that is not a problem. The child class can access and use these properties just like it can the methods.
But if the child class has new/unique properties of its own, then this is where we need to create __init__
and initialize everything slightly differently. Take a look at the code I have here below.
You can see in my parent constructor function I have a single property, this is name. This is followed by a single method, this method will just ask in english “What’s your name?”
Then I built out the child class Vietnamese
, here just like before I inherit the parent class Language
. Now since the child class will have a unique property only it has access to, we need to create a constructor for this child class.
Inside the child __init__
I first give the parameters that come from the parent class (name) followed by any new parameters made for this child class which here is, dialect
.
Before I even define the new property I need to “activate” the properties coming from the parent, superclass. This is done with the Python super()
function, followed by __init__()
.
The code here looks like super().__init__(name)
. If we translate that to english it just means, Initialize the property name from the superclass. Any property you wish to pass to the child needs to be initialized here.
Once you have done that then you can define any new properties for the child class as we normally would. When you make an object now you will need to give it two arguments, both name
and dialect
.
You can see where I printed everything out, this object has access to both properties and both methods now giving them the full scope of our code. Pretty cool, right?
This is really the essence or should I say basics of inheritance. I chose a simple class based example that we could see both routes to inheritance and hopefully you can see the routes we take and how we use them.
👉 I genuinely hope you get value from these articles, if you do, please help me out, leave it a ❤️, and share it with others who would enjoy this. Thank you so much!
My Best Starter Resources
Here are the best resources I have to offer to get you started with Python no matter your background! Check these out as they’re bound to maximize your growth in the field.
Code with Josh: This is my YouTube channel where I post videos every week designed to help break things down and help you grow.
Zero to Knowing: My Python Masterclass Subscription gives you everything you need to go from zero to building real-world projects — with new lessons, challenges, and support every month. Over 1,500+ students have already used this exact system to learn faster, stay motivated, and actually finish what they start.
My Books: Maybe you’re looking to get a bit more advanced in Python. I’ve written 3 books to help with that, from Data Analytics, to SQL all the way to Machine Learning.
Wrapping Up Lesson Sixteen
By now, you’ve got a solid grip on the second big idea in object-oriented programming—inheritance. Last time, we talked about encapsulation, and now you’ve seen how inheritance lets us build off a base class and pass stuff down to more specific ones. It’s a clean way to avoid repeating yourself and to keep your code more organized.
Whether you’re just borrowing from the parent class or adding new features to a child class, inheritance helps you write smarter, cleaner code that’s easier to manage and grow over time.
The main point here? Inheritance saves you time and effort while letting you do more with less code. Once you get the hang of it, you'll start to notice how much smoother your coding gets.
Next, we’re moving on to the third pillar—polymorphism—where classes can take on different forms. It’s a fun one, so be sure to stick around.
Let’s keep moving forward with Day #17 next week.
Hope you all have an amazing week nerds ~ Josh (Chief Nerd Officer 🤓)
👉 If you’ve been enjoying these lessons, consider subscribing to the premium version. You’ll get full access to all my past and future articles, all the code examples, extra Python projects, and more.
Thank you, this is very nice!