Welcome to the OOP in Python tutorial repository! This repository contains a series of Python scripts designed to teach the core concepts of Object-Oriented Programming (OOP). Each concept is explained with examples, and you can practise every one of them with hands-on exercises that grade themselves as you go.
New to programming? You do not need to install anything. Jump to Try it now and you will be running real Python code in your browser in under a minute.
- Try it now (no install needed)
- Introduction
- Getting Started
- Concepts Covered
- Interactive practice with instant feedback
- Code Examples
- Learning Path
- License
- Contributing
- Support
- Contact
Click the green button below. GitHub builds a full Python workspace for you in the cloud (this is called a Codespace) with everything already set up. Nothing to download, nothing to configure.
Once it opens:
- Wait a few seconds for the setup to finish. A small progress scoreboard prints in the terminal.
- Run any lesson, for example:
python 01_basic_oop_concepts.py - Open
exercises/practice.pyand start solving. Check your progress any time withpython check.py.
Prefer to work on your own machine instead? See Installation below.
Object-Oriented Programming (OOP) is a programming paradigm that organizes software design around data, or objects, rather than functions and logic. Python supports OOP principles such as:
- Classes and Objects
- Encapsulation
- Inheritance
- Polymorphism
- Abstraction
OOP helps in making code reusable, easier to maintain, and closer to real-world modeling. This repository aims to introduce these concepts step-by-step, with examples to make learning OOP in Python easy and interactive.
If you use the Try it now button above, you can skip this section entirely.
To work on your own machine you will need:
- Python 3.6 or higher installed on your system
- Check your version:
python --versionorpython3 --version - Download from python.org if needed
- Check your version:
- A text editor or IDE (recommended: VS Code, PyCharm, or any editor you are comfortable with)
- Basic understanding of Python fundamentals (variables, functions, loops)
-
Clone this repository:
git clone https://github.com/Kubomu/OOP-Python-Tutorials.git cd OOP-Python-Tutorials -
Install the tools used by the exercises (one small package, pytest):
pip install -r requirements.txt
The lesson files (
01_through06_) use only the Python standard library, so they run without this step. You only need pytest to grade the practice exercises.
-
Start with the introduction:
- Read
00_Intro.mdto understand what OOP is and why it matters
- Read
-
Follow the tutorials in order:
- Begin with
01_basic_oop_concepts.py - Progress through each numbered file sequentially
- Each file builds on concepts from previous lessons
- Begin with
-
Run the examples:
# Run any tutorial file python 01_basic_oop_concepts.py # Or use python3 if that's your command python3 01_basic_oop_concepts.py
-
Read the code carefully:
- Every file includes detailed comments
- Docstrings explain what each class and method does
- Expected outputs are noted in comments
-
Practise with the self-grading exercises:
- Open
exercises/practice.pyand fill in the parts marked# TODO - See Interactive practice with instant feedback for how the grading works
- Open
Learn the basics of classes and objects. Understand how to define a class and instantiate objects in Python.
Understand how encapsulating data and methods within a class can help protect the internal state of objects.
Learn how classes can inherit attributes and methods from other classes to promote code reuse.
Understand how polymorphism allows objects to be treated as instances of their parent class, and how method overriding works.
Learn how abstraction hides complex implementation details and shows only essential features to the user.
Explore Python's built-in methods (dunder methods) that allow you to customize the behavior of your classes.
Reading about OOP is one thing. Writing it yourself, and getting told immediately whether you got it right, is how it sticks. That is what the exercises/ folder is for.
How it works:
- Open
exercises/practice.py. There is one small exercise for each of the six concepts above. Each one has a# TODOwhere your code goes. - Fill in a
# TODOwith your own solution. - Ask for a friendly progress report:
You will see a scoreboard, one line per topic:
python check.py
[x] 1. Classes and Objects done [ ] 2. Encapsulation todo [ ] 3. Inheritance todo ... Solved 1 of 6 - Want the full detail on a result? Run the grader directly:
pytest
- Keep going until all six read
done.
If you get stuck on a topic, open its matching lesson file (01_ through 06_) for a worked example, then come back and try again. You cannot break anything, so experiment freely.
Working in a fork? When you push your solved exercises/practice.py to your own fork, GitHub automatically runs the same grader and shows a green check next to your commit once every exercise passes.
In this repository, each topic is covered in separate files, including:
00_Intro.md- Introduction to OOP01_basic_oop_concepts.py- Introduction to classes and objects02_encapsulation.py- Encapsulation and private attributes03_inheritance.py- Understanding inheritance in Python04_polymorphism.py- Using polymorphism for code reusability05_abstraction.py- Working with abstract base classes06_magic_methods.py- Understanding magic methods like__init__,__str__, and__add__07_exercises.md- A written list of extra exercises and two capstone projectsexercises/practice.py- Hands-on, self-grading exercises (start here after the lessons)check.py- Prints your exercise progress as a simple scoreboard
Here's the recommended order for working through this repository:
- 00_Intro.md - Understand OOP fundamentals and benefits
- 01_basic_oop_concepts.py - Classes, objects, and methods
- 02_encapsulation.py - Data hiding and access control
- 03_inheritance.py - Code reuse through inheritance
- 04_polymorphism.py - Flexible code with polymorphism
- 05_abstraction.py - Abstract base classes
- 06_magic_methods.py - Special methods and operator overloading
- exercises/practice.py - Solve the self-grading exercises, one per concept
- 07_exercises.md - Extra written exercises and capstone projects
Estimated time: 3 to 5 hours to complete all tutorials and basic exercises.
This repository is licensed under the MIT License. See the LICENSE file for more details.
Contributions are welcome! Here's how you can help:
- Report bugs - Open an issue if you find errors in the code
- Suggest improvements - Share ideas for better explanations or examples
- Add exercises - Propose new practice problems
- Fix typos - Submit pull requests for documentation improvements
Please feel free to fork this repository and submit pull requests.
If you find this tutorial helpful:
- Give it a star on GitHub
- Share it with others learning Python
- Provide feedback through issues or discussions
For questions or to share your solutions:
- Open an issue on this repository
- Email: Kubomuedwin@gmail.com
Happy coding and learning!