5.2 Python Object Model
Why everything in Python is an object, and the three properties every object has — identity, type, and value — with id() and type() examples.
Everything Is an Object
What Is It?
In Python, literally everything — numbers, strings, functions, even classes themselves — is an object with its own identity, type, and value.
Why Does It Matter?
This uniformity is why the same tools (type(), dir(), hasattr()) work on any value, no matter what kind it is.
Every Python value is an object with three properties: identity, type, and value.
Identity
What Is It?
A unique integer identifying an object for its lifetime — effectively its memory address in CPython.
How Is It Used?
id(x) returns it; the is operator compares two objects’ identities.
>>> a = 5
>>> id(a)
11755816
Type
What kind of object it is, and therefore what operations are valid on it. Retrieved with type().
>>> type(a)
<class 'int'>
Value
The actual data the object holds — 5, "hello", [1, 2, 3]. For mutable objects the value can change over the object’s lifetime; for immutable objects it cannot (see 5.9 Mutable vs Immutable Types).
Quick Interview Answer
“Every Python object has three properties: identity (a unique id, effectively its memory address in CPython, from
id()), type (what kind of object it is, fromtype()), and value (the actual data it holds). This uniform model is why the same tools —type(),dir(),hasattr()— work identically on any value, since everything, even a function or a class, is an object.”
Common Mistakes
- Confusing
id()(identity, a memory address) withtype()(what kind of object it is) — they answer completely different questions. - Comparing objects with
iswhen==(value equality) is what’s actually intended —ischecks identity, not value.
Add More Questions to This Guide
Know a question that should be here? Share it and help the community!
Open Google Form