Learn Before
Concept

Mutability

An object is mutable if its data can be changed after initialization. Inversely, an object is immutable if its data cannot be changed after creation. Lists are mutable, and tuples are immutable. This makes lists better suited for data which we anticipate will be modified. However, tuples (but not lists) can serve as dictionary keys. In addition to lists, dictionary objects are also mutable.

In Python, most data types are immutable, such as integers, floats, strings, tuples and booleans. Immutable data types are faster to use in code, but their values can only be changed by creating a copy of the object to be altered.

0

2

Updated 2021-06-22

Tags

Python Programming Language

Data Science