Overview, Historical Timeline, Problems & Solutions
An Overview of the Python Data Model
What is the Python data model?
The Python data model is the structure that controls how Python handles data. It defines what an object is, how it is stored, and how it behaves. The Python data model also defines how values are compared, changed, or grouped.
In Python, every value is an object. That includes numbers, strings, lists, and functions. Each object has three key parts: identity, type, and value. These parts help Python know what the object is and what it can do.
Python lets you treat all data as objects using the data model.
x = 5
print(type(x))
print(id(x))
The number 5
is an object. It has a type (int
), a value (5
), and an identity (shown by id()
).
How does the data model shape all Python behavior?
The Python data model shapes all parts of the language. It tells Python how to store values, compare values, and track memory. It also supports features like attributes, methods, containers, and garbage collection.
The data model controls how Python runs every program. It connects variables, functions, objects, and built-in types. It also helps Python know how to treat things like equality, order, and structure.
A Historical Timeline of the Python Data Model
Where does Python’s data model come from?
The Python data model follows from earlier computer science work. It was shaped by ideas from system memory, type theory, object models, and practical languages like C and ABC. This timeline shows the key ideas.
People invented ways to store and label data.
1945 — Stored program model, John von Neumann, defined memory layout where code and data are stored together.
1972 — Structured types in C, Dennis Ritchie, used structs, pointers, and types to shape memory directly.
1980 — Objects in ABC, Guido van Rossum’s source language, shaped the idea of values with identity and type.
People designed the Python object system.
1991 — Object model in Python 0.9.0, all values made into objects with fixed identity and type.
2000 — Garbage collection added, Python 2.0 added cycle-aware GC to extend reference counting.
2001 — __dunder__
methods, PEP 234 gave standard ways to hook into the data model using special methods.
People expanded how the model works.
2008 — Memoryview and buffer protocol, Python 3.0 added low-level support for memory-safe binary objects.
2018 — __class_getitem__
and typing, Python 3.7 expanded how type behavior and subscripted classes work.
2025 — No changes to object base, Python kept its original model stable: every value is an object.
Problems & Solutions with the Python Data Model
How does Python handle values, memory, and behavior?
The Python data model gives each value a fixed identity, a known type, and a possibly changing value. These real-world examples show how this system helps programs run clearly and safely.
Problem 1: Keeping track of a value
Problem: You write down a number on a sticky note and pass it to a friend. Later, your friend writes a new number on another note. You compare the notes to check if the numbers match.
Solution: Python uses objects with value and identity. You can compare the values with ==
, and compare the identities with is
.
Python lets you compare values and identities of objects.
a = 5
b = 5
print(a == b) # True
print(a is b) # May be True or False
The values may be the same, but Python may reuse or not reuse the object.
Problem 2: Reusing the same object
Problem: You buy two identical plastic cups. They look the same, but they are still two cups. You label each with a sticker. You can now tell them apart.
Solution: Even if two objects have the same value, they may have different identities. Python tracks each object using a unique ID.
Python lets you check object identity using id()
or is
.
x = [1, 2, 3]
y = [1, 2, 3]
print(x == y) # True: same value
print(x is y) # False: different objects
print(id(x), id(y))
Lists with the same contents are not the same object unless assigned directly.
Problem 3: Objects that never change
Problem: You write your name on a rock with paint. The rock keeps the same shape. The paint can wear off, but the rock does not change.
Solution: Python uses immutable types like numbers, strings, and tuples. Their value cannot be changed once created.
Python lets you use immutable objects for safe, fixed data.
name = "Ada"
print(name.upper()) # "ADA"
print(name) # still "Ada"
The method makes a new string. The old one stays the same.
Problem 4: Objects that hold other objects
Problem: You pack a suitcase with shirts. The suitcase stays the same, but the shirts inside can change.
Solution: Python containers hold references to other objects. Lists and dicts can change what they hold. Tuples cannot change what they point to, but the contents may still change.
Python lets containers hold and reference other objects.
shirts = ["blue", "green"]
suitcase = (shirts,)
shirts[0] = "red"
print(suitcase) # ('red', 'green')
Even though the tuple is immutable, the list inside it can change.
Problem 5: Letting go of objects
Problem: You throw away a box. If nothing points to it, the trash service will take it. But if someone still uses it, it stays.
Solution: Python uses automatic memory cleanup. When no name points to an object, Python may remove it.
Python lets the system clean up unused objects automatically.
def make_box():
box = [1, 2, 3]
return box
box = make_box()
del box # now box is gone, object may be cleaned up
Python may now delete the object, unless something else still holds it.
Like, Comment, Share, and Subscribe
Did you find this helpful? Let me know by clicking the like button below. I'd love to hear your thoughts in the comments, too! If you want to see more content like this, don't forget to subscribe to my channel. Thanks for reading!
Mike Vincent is an American software engineer and writer based in Los Angeles. More about Mike Vincent
Top comments (0)