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.

cog wheels

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

instructor-led training course

Enjoying this page? We offer live Python training courses covering the content of this site.

See: Live Python courses overview

Upcoming online Courses

Enrol here

In this chapter

1. Object Oriented ProgrammingGeneral introduction in object-oriented Programming and the way it is used in Python
2. Class vs. Instance AttributesObject-oriented programming in Python: instance attributes vs. class attributesand their proper usage.
3. Properties vs. Getters and SettersObject oriented programming in Python: instance attributes vs. class attributesand their proper usage.
4. Implementing a Custom Property ClassPython Class implementing a custom property class.
5. Introduction to DescriptorsIntroduction to descriptors. Defining descriptors, summarizing the protocol, and showing how descriptors are called.
6. InheritanceTutorial on Python: Inheritance
7. Multiple InheritanceObject-Oriented Programming in Python: Covering Multiple inheritance, the diamond problem, MRO and polymorphism in Python''
8. Multiple Inheritance: ExampleExtensive example of multiple inheritance in Python
9. Magic MethodsPython Tutorial: Magic methods and operator overloading with examples. __call__ method to turn class instances into callables
10. Callable Instances of ClassesPython Tutorial: Callables in Python and class instances which can be used like functions. Introduction in the __call__ method
11. Inheritance ExampleObject Oriented Programming: Example of Inheritance in Python.
12. Slots: Avoiding Dynamically Created AttributesSlots in Python: A way to prevent the dynamical creation of attributes and to save memory space in certain cases
13. Polynomial ClassPython Class implementing polynomial functions.
14. Dynamically Creating Classes with typeRelationship 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 MetaclassesIncentive and motivation for learning and using metaclasses. Example classes,which could be designed by using metaclasses
16. MetaclassesTutorial on Metaclasses, theory, usage and example classes using metaclasses
17. Count Function calls with the help of a MetaclassUse Cases for Metaclasses: Counting Function Calls
18. The 'ABC' of Abstract Base ClassesAbstract Classes in Python using the abc module