Utility · sources and further reading
Resources
Everything below is the canonical version of what this hub teaches. One heads-up: Automate the Boring Stuff, this course's usual second telling, deliberately skips classes, so for OOP the official tutorial is both the primary and the gentle path. Same rule as every week: when a random tutorial disagrees with these, these win.
Reference documents
| Document | Use it for | Nature |
|---|---|---|
| Python Tutorial: Classes | This week's core reading. Sections 9.1 to 9.4 cover everything the hub uses; inheritance (9.5) is worth a skim for the reading rules; the rest can wait for a later course | Official (PSF) |
| Python Tutorial: Data Structures | Lists, properly: section 5.1 is the full version of the "just enough lists" aside | Official (PSF) |
| PEP 8, the style guide | The naming conventions (CapWords classes, lowercase instances) and layout rules the whole Python world shares; skim the naming section now, return for the rest later | Official (PSF) |
| gpiozero: output devices · input devices | Real class documentation to practise reading: constructors, attributes, methods, and the "Bases:" lines the inheritance section decoded | Project docs |
| Object-oriented programming | The concepts and their history, Simula's simulation origins included, and the vocabulary (encapsulation, inheritance, polymorphism) in one place | Encyclopedic |
| Class (computer programming) · Composition over inheritance | The class idea across languages, and the professional argument behind this course's write-has-a advice | Encyclopedic |
Background reading, matched to the stages
| Stage | Read this for the ideas behind it |
|---|---|
| Objects you own | Tutorial 9.1 to 9.3 (scopes can be skimmed; the objects part read closely); the OOP article's history section for why simulation birthed the paradigm |
| First class | Tutorial 9.3 to 9.4 (class and instance variables, exactly today's material); Data Structures 5.1 for the list methods; PEP 8 naming |
| State & devices | The FSM article from Week 5, reread with attributes in mind; composition over inheritance for the has-a/is-a advice, argued at length |
| Build lab | Tutorial chapter 6 (Modules), first two sections, for the machinery behind your import; gpiozero's class pages as the model your docstrings imitate |
Practice
- Paper class katas. Spec then write, no computer:
Door(open/close/is_open),Thermostat(setpoint, current, needs_heating()),Counter(increment, reset, value),TrafficLight(three states, next()). One per day is midterm gold. - Refactor your history. Any Week 4 ladder script rebuilt as a class is a full workout: find the state, name the owner, extract the methods, verify behaviour unchanged.
- Trace method calls. Take
ReactionLog, invent three calls, trace them with aselfcolumn, then check in the REPL. The gap between table and interpreter is the study list. - Read one real class end to end. gpiozero's Button page: identify constructor arguments, attributes vs methods, what is inherited from where. Fifteen minutes, and library documentation stops being weather.
- Midterm drills. The review plan is the schedule; the hubs' checklists and quizzes are the question bank.
Glossary
| Term | Meaning |
|---|---|
| Class | The blueprint: attributes and methods every instance of this kind has. |
| Instance / object | One concrete thing built from a class, with its own state. |
| Attribute | State on an instance, reached by dot, no parentheses. |
| Method | Behaviour on a class, called through an instance, with parentheses. |
Constructor / __init__ | The method run at creation to set starting state; "dunder init". |
self | Inside a method, the instance being operated on; supplied by Python, listed by you. |
| Bound method | A method tied to its instance, passable as a value; what callbacks receive. |
| Class attribute | A name assigned in the class body, attached to the blueprint and seen by all instances. |
| Instance attribute | A name created through self, owned by one instance; the default for state. |
| Encapsulation | State changed only through the methods that know its rules. |
| Composition (has-a) | Building objects that contain other objects as attributes. |
| Inheritance (is-a) | Defining a class as a specialization of another; the "Bases:" lines. |
| Docstring | The string first line of a def or class; what help() shows. |
| Module | A .py file importable by its name; today, yours. |
| Refactoring | Changing structure while preserving behaviour, proven by re-run checks. |
| Dunder | Double-underscore names like __init__: Python's hooks into your class. |