When you write:
x = 10
Python doesn't really put
10 inside a box called x. 10 is an object, and x is simply a name that refers to that object. 👉 You can see this more clearly:
x = 10
y = x
print(x is y)
True
Both
x and y are pointing to the same object. This is also why is and == are different:a = [1, 2, 3]
b = [1, 2, 3]
print(a == b) # True
print(a is b) # False
The values are equal, but they are two different list objects. 📦
And this idea isn't limited to numbers and lists. In Python, almost everything you work with is an object - strings, functions, classes, dictionaries, and even modules.
Start with this mental model:
Names point to objects. Objects have a type, value, and identity.
That's the Python object model in its simplest form. ✅
Want more Python concepts explained simply❓
👉🏾Follow the channel so you don't miss them.
