Python Day #18: What Is Abstraction in Object-Oriented Programming?
See what abstraction in object-oriented programming means, why it matters, and how to use it in Python with simple real-world examples.
We’ve covered the essence of Object-oriented programming in the last few lessons. Today it’s time to touch on the fourth and final pillar of OOP, Abstraction.
So far we’ve covered classes and objects and exploring the first three pillars. These being: Encapsulation, Inheritance and Polymorphism.
All big words and concepts to those looking in on the outside. But here I broke it all down to concrete steps to teach you guys exactly what these are and how we implement them to better structure out our code.
In this lesson, we’re moving on to the final pillar of OOP — one that will close out our journey of OOP, Abstraction. No, I’m not talking about abstract art, although code is really just art that does something. This is a new form of Abstraction.
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!
Boiling it down, Abstraction is really the concept of hiding more complex details and only showing the key features of an object to the user.
It allows for us to interact with an object through a simplified interface, without needing to understand the intricate internal workings. Making them easy to deal with and really allow us to create a more reusable flow to our code.
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!
Each week’s lesson is designed to build directly on the last, giving you the tools and logical thinking skills you need to create a solid programming foundation.
Recap of Polymorphism in OOP
Let’s do a quick recap on the term, Polymorphism so we can keep building on this concept of Abstraction.
Polymorphism lets us to define a method in the parent class and then override it in child classes, each giving it a different behavior.
Why in the world would I want to do this? Well because it allows you to write code that’s more flexible, scalable, and easier to maintain.
You can call the same method name without worrying about which exact type of object you’re working with because Python will figure it out at runtime.
Think of it like this: If I tell both a dog and a cat to “speak,” the dog is hopefully going to bark, and the cat might meow. At least I hope that’s what we would hear. The command is the same, but the response depends on the object.
👉 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!
Abstraction in Object-Oriented Programming
Simply put, abstraction is really just about keeping things simple. It hides the complicated details and only shows you the parts you actually need to work with.
Think about driving a car. You don’t need to understand how the engine burns fuel, how the gears shift, or how the brake system works. All you care about is that when you press the gas pedal, the car moves forward.
That’s abstraction—you get a simple way to interact with something, while all the complicated stuff stays hidden under the hood.
In programming, it works the same way. Abstraction lets us create methods that act like rules or guidelines. The parent class says, “These methods need to exist,” but it’s up to the child classes to decide how those methods actually work.
The Fourth Pillar of OOP in Action
Let’s talk about why we’d even use abstraction and what it really does.
Say we have a parent class called Animal
. Inside that class, we create a method called speak()
. But here’s the thing—by default, this method doesn’t actually do anything.
The reason is simple: every animal makes a different sound. A dog barks, a cat meows, a cow moos. We don’t know the details yet, but we do know that every animal should be able to “speak” in its own way.
So in the parent class, we just set up the method and leave it empty with the pass
keyword. That’s our way of saying, “Every animal needs this method, but the child classes will decide how it works.”
Here’s the key point: when a class like Dog
or Cat
inherits from Animal
, it’s required to actually write out the speak()
method. If it doesn’t, Python will throw an error and remind us we skipped something.
That’s the real strength of abstraction. It makes sure every class that inherits from the parent sticks to the same rules, so no matter how many animals we create, they’ll all have a speak()
method, and none of them can forget to implement it.
Take a moment and look through the code above. Notice the imports I have and the decorator function I use in the ABC (Abstract Base Class). This is what really creates the structure of an ABC class.
👉 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
My masterclass is designed so you see your first win in less than 7 days — you’ll build your first working Python scripts in week one and finish projects 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.
Abstraction in Code
Let me now move away from the classic animal or car examples for a second and look at something a bit more real-world.
Let’s think about a payment system. No matter what kind of payment it is, the one thing we know for sure is that it has to be processed. But how it gets processed depends on the type of payment.
A credit card charge works one way, PayPal works another, and if you throw cryptocurrency into the mix, that’s different too.
While these are all forms of payment and the merchant still receives their money one way or another, they are all different. This is exactly where abstraction comes into play.
We could create a parent class called Payment
. This parent class doesn’t actually know how to process a payment.
Instead, it just sets the rule: “Every payment type must have a method called process_payment(amount)
.” This makes sure anyone who inherits this class follows these given rules that we set for our program.
Notice how the method has no code inside it? I just gave it the keyword, pass. This is just use creating a method which is acting like a rule. It’s because we’re not telling Python how to process the payment here. We’re just saying that every payment class must have this method.
Now that there is the idea of a payment processor we can build out some classes for the different forms of payment like I have below.
These two children are inheriting the Payment class and then they are completing the payment_process method which is completing the rule that we set for the method.
Then we can try them out. Here is a great time to tie in polymorphism as we covered this in the last lesson. Abstraction and Polymorphism work really well together so we can now use them together.
The whole thing of Abstraction here is not fancy art, no. But rather the parent class (Payment) laid down the rule, and the child classes (CreditCardPayment and PayPalPayment) filled in the details in their own way.
Now let’s say your app needs to support Bitcoin payments later becasue we are in the crypto age. You don’t have to rewrite any of your existing code. You just add a new class:
And just like that, it fits right in with the others.
That’s the whole idea behind abstraction. It lets you hide the messy details and just focus on the important part: making sure the right methods exist. It keeps your code organized, easier to maintain, and ready for the future.
👉 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 Eighteen
Abstraction sounds like another big word, but at its core it’s pretty simple. It’s just about focusing on what’s important and hiding the stuff you don’t need to see.
By setting up abstract classes and methods, you create a kind of blueprint that makes sure every child class follows the same rules, while still letting each one do things in its own way.
The benefit is huge: your code stays cleaner, easier to work with, and ready to grow. If you ever need to add something new—like another payment option, a new feature, or a new type of object—you don’t have to rip your code apart. You just build a new class, give it the methods it needs, and it fits right in.
It’s the same idea as using your phone. You tap an app, it opens, and you use it. You don’t need to know what’s happening behind the scenes, you just care that it works. That’s abstraction in action.
With this, you’ve now learned three of the four pillars of object-oriented programming: Encapsulation, Inheritance, Polymorphism, and Abstraction.
Let’s keep moving forward with Day #19 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.