Wiston Venera Macías
2 min readJan 18, 2021

--

Mutable, Immutable… everything is an object!

It is interesting to know that Python loads in memory a list of integers to make the program a little faster. Maybe this is one of the reasons why python is not so fast in general but it does its best to be better.

Because python manages memory automatically, it is necessary to know when python is giving you something new or just pointing to something that already exists. For that reason, there is a function called id(), with which you can know the memory address of a variable. There is also another function called type() to know the type of variable you are using. And this is necessary because python is not a strongly typed language. A good analogy would be that id() is to know your ID number and type() to know what gender you are.

In Python certain types are immutable and others are mutable. Numbers, strings, and tuples are immutable. Lists, on the other hand, are mutable.

Python treats all variables as references to the object. This means all variables store the memory address of the actual object. This concept is much like “Pointer” in the C programming language. This means the address of the actual object is stored in the Python named variable, not the value itself.

Every time you change the value of an immutable object, a new object is created. The old object is discarded and memory is cleaned up by garbage collector automatically.

--

--