2.1.3 · D1OOP Fundamentals

Foundations — Instance attributes vs class attributes

1,639 words7 min readBack to topic

Before you can follow a single line of the parent note, you need to read its symbols with zero guessing. This page builds each one from nothing — plain words first, then a picture, then why the topic can't live without it. Read top to bottom; each idea is a brick for the next.


1. class X: — the blueprint keyword

The picture: think of a cookie cutter. It is not a cookie — you can't eat it — but it defines the shape every cookie will have. class Dog: is the cutter; it doesn't bark, but it decides what a dog is.

Figure — Instance attributes vs class attributes

2. The object (a.k.a. instance) — one produced thing

The picture: from one cutter you stamp out many cookies. Each cookie is separate — bite one, the others are untouched.

Figure — Instance attributes vs class attributes
Recall Why "instance" and "object" are the same word

"Instance" stresses "an instance of the Dog blueprint"; "object" stresses "a thing in memory." They point at the identical cookie. The parent note uses both.


3. = in Python is naming, not equation

This single distinction is the hinge of the whole topic. The parent note keeps repeating "there is no assignment" or "this is an assignment." An assignment is exactly the presence of a bare = (not ==, not .append). See Namespaces and scope for where these labels are filed.


4. self — the "this particular object" handle

The picture: each cookie carries a little name-tag that says "me." self is that name-tag while a method runs.

Figure — Instance attributes vs class attributes

5. __init__ — the setup ritual

The picture: as each cookie pops out of the cutter, a decorator immediately writes its personal details (name, own empty list of tricks) onto it — before anyone else touches it.


6. . (the dot) — "look inside"

Crucially, the dot behaves differently depending on which side of the = it sits on:

The picture: reading is "search my notebook, then the whiteboard"; writing is "always scribble in my own notebook." This asymmetry is the engine behind every tricky behaviour in the parent note.


7. __dict__ — the actual storage drawer

The picture: a labelled drawer. The cookie's drawer starts with {"name": "Rex"}. The cutter's drawer holds {"species": "Canis familiaris"}.


8. Mutate vs reassign — two different actions

The picture: reassigning = handing you a different box; mutating = opening the same box and adding an item. a.tricks.append("roll") mutates the one shared list; nobody got a new box, so both dogs see the change. Foundation for this: Mutable vs immutable objects.


9. MRO — the search order for classes

The picture: notebook → front whiteboard → the whiteboard in the previous classroom you inherited from, and so on, until found. The parent note names this as step 3 of lookup. Full story: Inheritance and MRO.


The prerequisite map

class X colon blueprint

object or instance

equals is naming not equation

mutate vs reassign

self the this handle

dunder init setup

the dot look inside

read write asymmetry

dunder dict storage drawer

mutable class attr trap

Instance vs class attributes

MRO base class search

Every arrow points toward the topic: get comfortable with the boxes on the left and the parent note reads like plain English.


Equipment checklist

Cover the right side and test yourself — you are ready when all reveal cleanly.

What does the class keyword introduce — a thing or a kind of thing?
A kind of thing (a blueprint / cookie cutter), not a concrete object.
Are "object" and "instance" different concepts?
No — same thing: one concrete item built from the class.
In Python, does x = 5 state a permanent equation?
No — it sticks the label x on value 5; it's an action you can redo.
What is the sign that an assignment happened?
A bare = (not ==, not .append(...)).
What does self refer to inside a method?
The specific object the method was called on.
When does __init__ run, and how often?
Automatically, once, at the moment each new object is created.
On a READ (print(obj.x)), what search order does the dot follow?
Instance __dict__, then class, then base classes (MRO).
On a WRITE (obj.x = ...), where does the value always land?
On the instance (obj.__dict__); never on the class.
What lives inside an object's __dict__?
Its personal name → value attribute pairs.
What is the difference between mutating and reassigning a list?
Mutate = change the same object's insides (.append); reassign = point the label at a new object (=).
What is the MRO?
The fixed order Python searches base classes when a name isn't on the instance or class.

Connections