2.7 Classes and objects
You can model a domain with classes rather than nested dicts.
Before:00. Orientation & SetupUnlocks:03. Data Handling & Analysis04. Classical AI — Agents, Search & Knowledge Representation
Classes model a domain — a dataset, an experiment, a pipeline stage — as a thing with state and behaviour instead of a tangle of nested dicts, and the libraries ahead, from PyTorch modules to sklearn estimators, assume you read and write them. It opens the object-oriented run. The counter-habit it teaches alongside is knowing when not to: where there is no state to hold, a plain function is better than a class with one method.
Work through these
__init__, instance vs. class attributes
The initialiser, and the difference between data belonging to one object and data shared by all of them. That distinction causes a memorable bug the first time it is missed.
Methods, staticmethod, classmethod
Ordinary methods, ones that need neither the instance nor the class, and ones that receive the class itself. Each has a small set of natural uses.
Encapsulation conventions in Python
Python signals intent about privacy by naming convention rather than enforcing it. Understanding that this is a social contract rather than a barrier explains a lot of library code.
The Python Tutorial · DocsWhen a function is better than a class
Not every collection of related functions needs to be a class, and a class with one method and no state is usually a function. Knowing when not to reach for one is part of the skill.
Sign in to keep your progress.
Free resources
We haven't checked most of these for screen reader use yet.
Links last checked 29 Aug 2026.
Stuck here?
Ask a mentor. A real person answers, and they can see exactly which topic you're on. Usually within a couple of working days.
Checking your session…
Topics shown in module order.