Object-Oriented Python
Classes bundle data and behaviour together. These lessons build from a single class to class methods, encapsulation, properties, special methods, inheritance, polymorphism, composition and dataclasses.
- 1Python Classes and ObjectsA class is a blueprint that describes what data a kind of thing holds and what it can do; an object is one co…✓
- 2Python Class Attributes vs Instance AttributesA class attribute is a variable stored once on the class and shared by every object, while an instance attrib…✓
- 3Python Class Methods and Static MethodsA class method receives the class itself (cls) instead of one object, which makes it ideal for alternative co…✓
- 4Python Encapsulation: Public, Protected and PrivateEncapsulation means keeping an object's data behind a small set of public methods that check every change, so…✓
- 5Python @property: Getters and SettersA property is a method that Python lets you use like a plain attribute, so obj.price looks like simple data a…✓
- 6Python Dunder (Magic) MethodsDunder methods are specially named methods such as __len__ and __add__ that Python calls behind the scenes wh…✓
- 7Python InheritanceInheritance lets a new class (the child) start with all the attributes and methods of an existing class (the …✓
- 8Python Polymorphism and Duck TypingPolymorphism means different kinds of objects respond to the same method call in their own way, and in Python…✓
- 9Python Multiple Inheritance and MROMultiple inheritance means a class lists more than one parent, such as class Duck(Swimmer, Flyer); Python the…✓
- 10Python Composition: Has-A vs Is-AComposition means building a class out of other objects it holds as attributes (a Car has an Engine) and dele…✓
- 11Python Abstract Classes (ABC)An abstract class is a base class that lists the methods every child must provide without saying how they wor…✓
- 12Python DataclassesA dataclass is a normal class where you list the fields once, with type hints, and Python writes __init__, __…✓
Start with Python Classes and Objects →
About Object-Oriented Python
Object-oriented programming models real things as objects that carry data and behaviour. Learn classes and objects, instance and class attributes, static and class methods, encapsulation, properties, dunder methods, inheritance, polymorphism, multiple inheritance, composition, abstract classes and dataclasses. The aim is to know not only how each feature works but when composition beats inheritance.
Related reference: Python OOP cheat sheet · staticmethod vs classmethod
Further reading (official documentation)
Practice for this topic
Python Classes and Objects exercises
4 exercises · checked in your browser
Python Class Attributes vs Instance Attributes exercises4 exercises · checked in your browser
Python Class Methods and Static Methods exercises4 exercises · checked in your browser
Python Encapsulation: Public, Protected and Private exercises4 exercises · checked in your browser
Python @property: Getters and Setters exercises4 exercises · checked in your browser
Python Dunder (Magic) Methods exercises4 exercises · checked in your browser
Python Inheritance exercises4 exercises · checked in your browser
Python Polymorphism and Duck Typing exercises4 exercises · checked in your browser
Python Multiple Inheritance and MRO exercises4 exercises · checked in your browser
Python Composition: Has-A vs Is-A exercises4 exercises · checked in your browser
Python Abstract Classes (ABC) exercises4 exercises · checked in your browser
Python Dataclasses exercises4 exercises · checked in your browser