The rules, again
Same game as chapter 1: read the question, commit to a prediction, run it, and only then open the answer. Wrong prediction means the drill goes on your redo list for three days from now.
Python's object system has less magic than it looks. self is an ordinary argument, methods are ordinary functions, and every operator you have used since chapter 1 was secretly a method call. This chapter makes that machinery visible, then drills the places it bites: shared class attributes, the MRO, and equality that compares addresses when you expected values.
Rusty on the basics? Work through Classes and Objects on learnpython.org first, then come back and drill.
One idea before you start
Every "magic" behavior in this chapter routes through one mechanism.
The drills
Click a question to open it. The answer stays hidden until you ask for it. Predict first.
Want more drills?
When these stop surprising you, let an AI generate fresh ones. Copy this prompt into ChatGPT, Claude, or any assistant you like:
You are my Python drill coach. Quiz me on: classes, self, class vs
instance attributes, inheritance and super(), method resolution order,
duck typing, @property, and dunder methods (__init__, __repr__,
__eq__, __len__, __getitem__, __call__).
Rules:
- Ask ONE question at a time. Show a short code snippet and ask me to
predict the output (or the error) before running it.
- Wait for my answer. Do not reveal anything until I reply.
- If I am right, say so in one line and raise the difficulty slightly.
- If I am wrong, explain the why in 2-3 sentences, then give me a
similar question later to check I really got it.
- Prefer tricky edge cases over textbook questions: a mutable class
attribute shared across instances, forgetting self, d.bark vs
d.bark(), diamond inheritance and mro(), __eq__ killing hashability,
name mangling with __attr.
- Keep score. After 10 questions, list the concepts I missed so I can
add them to my redo list.
Start with a medium question.The predict-first rule matters more than the tool. Whatever generates the questions, always commit to an answer before you look.
Done?
Score yourself honestly and queue up your misses. The shared-list drill (number 6) is chapter 5's mutable default wearing a class costume, and noticing that reuse is the real lesson: mutate vs rebind explains half this series. If drill 8's MRO went smoothly, you are ready for any inheritance question an interviewer can construct.
Next chapter: error handling, where try/except grows an else, finally runs even when you return, and context managers retire your cleanup boilerplate.