Intro to Object Oriented Programming
By Bernd Klein. Last modified: 01 Feb 2022.
This section of our Python tutorial deals with object-oriented programming, usually abbreviated as OOP. It is difficult to summarize the essence of object orientation in a few sentences:
Object Oriented Programming (OOP) is a programming paradigm based on the concept of "objects" that can contain data and code. The data is often implemented as attributes. Functions implement the associated code for the data and are usually referred to in object oriented jargon as methods. In OOP, computer programs are designed by being made up of objects that interact with each other via the methods.
It was difficult for us to decide whether to add object-oriented programming to the beginner or the advanced level sections of our Python tutorial.
There are some who think it's best to combine learning Python with OOP from the start. This is vital in programming languages like Java. Python can be used without programming in an OOP style. Many beginners to Python prefer this, and if they only want to write small to medium-sized applications, this is good enough. However, for larger applications and projects, it is recommended to look into OOP. The following chapters describe almost all aspects of Python OOP.
We decided to introduce the basics of Python without going directly into object-oriented programming. Therefore, these chapters assume that you are familiar with the basics of Python.
Live Python training
Enjoying this page? We offer live Python training courses covering the content of this site.
Upcoming online Courses
In this chapter
|1. Object Oriented Programming||General introduction in object-oriented Programming and the way it is used in Python|
|2. Class vs. Instance Attributes||Object-oriented programming in Python: instance attributes vs. class attributesand their proper usage.|
|3. Properties vs. Getters and Setters||Object oriented programming in Python: instance attributes vs. class attributesand their proper usage.|
|4. Implementing a Custom Property Class||Python Class implementing a custom property class.|
|5. Introduction to Descriptors||Introduction to descriptors. Defining descriptors, summarizing the protocol, and showing how descriptors are called.|
|6. Inheritance||Tutorial on Python: Inheritance|
|7. Multiple Inheritance||Object-Oriented Programming in Python: Covering Multiple inheritance, the diamond problem, MRO and polymorphism in Python''|
|8. Multiple Inheritance: Example||Extensive example of multiple inheritance in Python|
|9. Magic Methods||Python Tutorial: Magic methods and operator overloading with examples. __call__ method to turn class instances into callables|
|10. Callable Instances of Classes||Python Tutorial: Callables in Python and class instances which can be used like functions. Introduction in the __call__ method|
|11. Inheritance Example||Object Oriented Programming: Example of Inheritance in Python.|
|12. Slots: Avoiding Dynamically Created Attributes||Slots in Python: A way to prevent the dynamical creation of attributes and to save memory space in certain cases|
|13. Polynomial Class||Python Class implementing polynomial functions.|
|14. Dynamically Creating Classes with type||Relationship between classes and type for advanced programmers: deeper insight into what happens when we define a class or create an instance of a class.|
|15. Road to Metaclasses||Incentive and motivation for learning and using metaclasses. Example classes,which could be designed by using metaclasses|
|16. Metaclasses||Tutorial on Metaclasses, theory, usage and example classes using metaclasses|
|17. Count Function calls with the help of a Metaclass||Use Cases for Metaclasses: Counting Function Calls|
|18. The 'ABC' of Abstract Base Classes||Abstract Classes in Python using the abc module|