Everything is Object: Understanding Python Under the Hood
Introduction
You think Python is just about print("Hello world") and cute snake logos? Think again.
Python is a deeply object-oriented language, where everything is an object. And I mean everything. From the humble integer 1 to a list full of lists that contains a tuple of dictionaries — Python handles it all through its elegant object system. This project helped me uncover what's really going on in memory when we assign variables, compare them, and pass them around in functions. Buckle up, we're going under the hood.
id() and type() – Your Best Debugging Buddies
In Python, every object has two essential properties:
- its type, returned by
type(), tells you what it is (int, list, tuple, etc.), - its identity, returned by
id(), tells you where it lives in memory (kind of like its home address).
When the values are the same, == returns True. But is only returns True when the two variables point to the same exact object in memory. id() is how we check that:
Mutable Objects — Change is Their Nature
Mutable objects are objects that you can change in place. Lists are the classic example.
Assignment doesn’t always mean copy. If you do:
Both a and b refer to the same object. It's like giving two people keys to the same house. If one of them adds a sofa, the other will find it too.
Immutable Objects — Frozen in Time
Immutable objects cannot be changed after creation. Strings, integers, and tuples are the main stars of this category. When you try to “modify” them, Python actually creates a new object behind the scenes.
Why Does It Matter?
Because Python treats mutable and immutable objects differently, especially when passing them around or modifying them.
Function Arguments: The Hidden Twist
Python passes references to function parameters — not copies.
Get Clarisse Perez’s stories in your inbox
Join Medium for free to get updates from this writer.
So:
The list was changed because it was mutable, and the function had a reference to the same object.
But:
Here, x is an int (immutable). The function tried to reassign it, but that only affected the local variable n, not x.
Moral of the story? Passing a list to a function is like handing someone your diary. Passing an int is like giving them a photocopy.
Conclusion
This project taught me to see through Python’s illusions. Variables are just names. Objects live in memory. Some change, some don’t. And if you know who’s mutable and who isn’t, you’ll be a lot less surprised when your functions return unexpected results or your data structures behave oddly.
And now I know: is and == are not the same, id() is my new best friend, and += is not as innocent as it looks.



