Mutable vs Immutable Objects in Python

 

https://medium.com/@meghamohan/mutable-and-immutable-side-of-python-c2145cf72747

 

Everything in Python is an object.
Since everything in Python is an Object, every variable holds an object instance. When an object is initiated, it is assigned a unique object id. Its type is defined at runtime and once set can never change, however its state can be changed if it is mutable.

Simply put, a mutable object can be changed after it is created, and an immutable object can’t.

 

Mutable objects:
list, dict, set, byte array

 

Immutable objects:
int, float, complex, string, tuple, frozen set [note: immutable version of set], bytes

 

Share: