ThePythonBook

Object-Oriented Programming

Classes, inheritance, magic methods, dataclasses, and design patterns

13tutorials
76exercises
315minutes
1155XP
13 tutorials in this category

Python Classes and Objects: OOP from the Ground Up

Learn Python classes and objects from scratch. Understand __init__, self, instance methods, class attributes, and __str__ with interactive examples and exercises.

intermediate30m795

Python Inheritance: Subclasses, Polymorphism, and super()

Master Python inheritance — create subclasses, override methods, use super(), and understand polymorphism with interactive code examples and exercises.

intermediate25m685

Python @classmethod vs @staticmethod: When to Use Each

Learn the difference between @classmethod and @staticmethod in Python. Master factory methods, utility functions, and when to use each decorator with hands-on exercises.

intermediate20m570

Python @property: Getters, Setters, and Computed Attributes

Master Python @property decorator to create getters, setters, deleters, and computed attributes with validation. Learn encapsulation through hands-on exercises.

intermediate20m690

Python Magic Methods: The Complete __dunder__ Guide

Master Python magic methods (dunder methods) including __str__, __repr__, __len__, __eq__, __lt__, __getitem__, __contains__, and __call__ with interactive exercises.

advanced30m8120

Python Operator Overloading: Make Classes Work with +, -, ==

Learn Python operator overloading with __add__, __sub__, __mul__, __eq__, __radd__, and __iadd__. Build custom classes that work with arithmetic and comparison operators.

advanced25m695

Python Abstract Base Classes: Enforce Interfaces with ABC

Learn how to use Python\

advanced25m585

Python Multiple Inheritance and MRO: How It Actually Works

Understand Python multiple inheritance, the diamond problem, Method Resolution Order (MRO), super() in complex hierarchies, and practical mixin patterns.

advanced25m595

Python Dataclasses: Less Boilerplate, More Readable Code

Master Python dataclasses to eliminate repetitive __init__, __repr__, and __eq__ boilerplate. Learn @dataclass, field(), __post_init__, frozen classes, and comparison.

intermediate25m7105

NamedTuple vs TypedDict vs Dataclass: Which to Choose?

Learn when to use NamedTuple, TypedDict, or dataclass in Python. Compare structured data containers with interactive examples and exercises.

intermediate20m570

Python __slots__: Reduce Memory Usage by 40%

Learn how __slots__ works in Python to reduce memory usage and speed up attribute access. Interactive examples with memory comparisons.

advanced20m575

Advanced Dataclasses: __post_init__, frozen, field(), slots, and Inheritance

Master advanced dataclass features including validation with __post_init__, immutability with frozen, complex defaults with field(), and dataclass inheritance patterns.

advanced25m690

Composition vs Inheritance: Why \

Learn when to use composition over inheritance in Python. Understand has-a vs is-a relationships, dependency injection, and how to refactor fragile inheritance hierarchies.

advanced25m580