Classes, inheritance, dataclasses, decorators, and an honest look at when a function is the better answer.
Before this guide: Python from the Start.
The notebooks
Open in Colab runs a notebook in your browser, and Read shows it on GitHub without running it. Every notebook runs on its own, and the answers to its exercises are in a separate notebook, linked as Solutions.
| 1 | Why ClassesThe problem they solve, and three cases where a function is better | Open in ColabReadSolutions |
| 2 | Your First Class__init__, attributes, and self demystified | Open in ColabReadSolutions |
| 3 | MethodsBehavior that belongs to the object, and what self is doing | Open in ColabReadSolutions |
| 4 | Dunder Methods__repr__, __str__, __eq__, and making your object printable | Open in ColabReadSolutions |
| 5 | Context Managers and IteratorsWriting the objects behind with and for | Open in ColabReadSolutions |
| 6 | DecoratorsWhat the @ line does, and writing one of your own | Open in ColabReadSolutions |
| 7 | PropertiesComputed attributes, and validation without a getter for everything | Open in ColabReadSolutions |
| 8 | Class and Static MethodsAlternative constructors, and methods that need no instance | Open in ColabReadSolutions |
| 9 | InheritanceSubclassing, super(), and the method resolution order | Open in ColabReadSolutions |
| 10 | Composition over InheritanceThe case against the hierarchy you were about to build | Open in ColabReadSolutions |
| 11 | DataclassesMost of the above, for free, in one decorator | Open in ColabReadSolutions |
| 12 | InterfacesAbstract base classes, Protocols, and declaring what you require | Open in ColabReadSolutions |
| 13 | Exceptions as ClassesYour own exception hierarchy, and what to put in it | Open in ColabReadSolutions |
| 14 | Worked DesignsShapes side by side with functions, a playlist and notification channels, then a design of your own | Open in ColabReadSolutions |