What are mutable and immutable data types in Python?

Every types in Python is an object and all objects in python are either mutable or immutable types.

Mutable data types are those data types whose state can be changed even after runtime. For example: List, Set and Dictionary are mutable data types. Similarly customs classes are also mutable. The mutable data types are discussed as follows:

  1. List: It is mutable sequence of objects. It is created by placing all the elements inside a squared bracket [ ]. It contains sequential placement of elements.
  2. Set: It is unordered set of distinct objects.
  3. Dictionary: It deals with associative mapping i.e. a key is mapped or associated to a value where the values can be of any data types. Dictionary are unordered key-value pairs.

Whereas immutable data types are those whose values cannot be changed once it is defined at runtime. They include Boolean value, integer, float, tuple, string and frozenset.