Classes and objects
corebeginnerA class defines the shape something has — its attributes and behaviour. An object is one concrete thing built from that shape. class Dog: defines the blueprint; Dog() builds an object from it.
Think of it as
A class is a cookie cutter; an object is one cookie. The cutter defines the shape every cookie will have, but cutting it does not use up the cutter — you can stamp out as many independent cookies as you like, each one its own dough.
What we're doing: Define a bare class, build two objects from it, and show they are independent.
- 1
- class Dog: pass defines the blueprint. It builds nothing by itself.
- 4
- Dog() calls the class, which constructs and returns one new object — bound to rex.
- 5
- A second call to Dog() builds a completely separate object, bound to fido.
- 7
- Setting rex.name only touches rex — fido was never given a name attribute.
Rex
False
False
TrueWhy this works: Dog() is a call to the class itself, and every call constructs a fresh, independent object — nothing about one object's attributes is shared with another unless the class deliberately arranges that (see class attributes). rex and fido are both built by Dog, so type(rex) is Dog is True and isinstance(rex, Dog) would be too, but rex is fido is False because identity checks the specific object built, not which class built it.
Expecting Dog() to reuse a previously built object
Wrong
Better
What you see: AttributeError: 'Dog' object has no attribute 'name' — the new object never saw the name set on the first one.
Why: Every call to Dog() builds a brand-new, empty object — it does not look up or reuse any object built by an earlier call. To refer to the same object again, bind a second name to it directly (another_rex = rex), rather than calling the class a second time.
- class Dog — the blueprint — no dog yet
- Dog() — called twice, independently
- rex, fido — two distinct objects, same shape
Class vs. the objects it builds
Together
Remember: A class is the blueprint; Name() builds one independent object from it. type(obj) and isinstance(obj, Name) both ask which blueprint built it.
See also: constructors · instance attributes · class attributes

