
Everything(all values) in Python is an object or a class. What does it mean exactly? Everything is an object in the sense that it can be assigned to a variable or passed as an argument to a function. Almost everything has attributes and methods.
For example an integer in Python is an object, a large block of “structured” memory, typically over 100 bits long, and different parts of that structure are used internally to the interpreter.
In the next image, references to objects “Hello” and [1, 2] are created. In both cases, the variables don’t actually hold the data, but simply direct access to it.

id and type
Each object in python has an identity and a class it belongs to. The identity corresponds to an integer (or long integer) value which is unique to every object during its lifetime in a program. Two objects with different life times can have the same id value.
id
In order to obtain the identity of an object, the built in function id(object) is used.
In this example, an object with value “2” is created in memory and referenced through the identifier “a”. When id(a) is used and printed, a numeric value in shown.

If the program is run again, the value for the same object can change, as it is simply a representation of the object in memory (similar to a memory address).

type
And of course, each variable has it’s own type. As we all know, everything in python belongs to a certain class. so even types are actually classes. And to access a certain variable’s type we use the type() function. here are some examples;

Mutable and immutable objects:
Whenever an object is created, it is assigned a unique object id. The type of the object is defined at the runtime and we can’t change it later. Now is it’s state can be changed, it is a mutable object, and if it can’t means it’s immutable.
Mutable object: lists, dict, set
Immutable object: int, float, complex, string, tuple, frozen set [note: immutable version of set], bytes
To find out if an object is mutable we try a simple example

And now, we know for sure that lists are mutable since we can change a certain value in a list.
let’s see tuples:

So, we were able to append more elements to the tuple, but we couldn’t change a certain value. that’s what immutable is.
Why does it matter and how differently does Python treat mutable and immutable objects
It is important to know how python handles mutable and immutable objects in order to avoid getting errors or modifying data when that is not the desire.
An example of this can be shown with a list, a mutable object.

In this case, a list is created with the variable “a”. After that, “b” gets an assignment as if creating a copy, but when “b” is modified and then “a” is printed, the result is as if “a” had been modified instead of “b”.
The reason for this can be seen in the frames and objects space, where it is shown that both variables are actually pointing to the same object instead of different ones.
In order to do things with a copy, a different approach would have to be taken. A possibility would be to use a list method to create a copy.

It is also important to take into account that when mutable objects are modified, no new object is created, so the id is kept the same.

In the case of immutability, there must be precaution when data is modified in order to avoid errors.