what is mutable and immutable types in python
Answers
Answer:
The Mutable Data Types in python are:
i) list
ii) dictionary,
iii) set and
iv) user-defined classes.
The Immutable Data Types in python are:
i) int
ii) float
iii) decimal
iv) bool
v) string
vi) tuple
vii)range
Explanation:
Every variable in python holds an instance of an object. There are two types of objects in python i.e. Mutable and Immutable objects. Whenever an object is instantiated, it is assigned a unique object id.
Mutable Objects: The type of the object is defined at the runtime and it can’t be changed afterwards. However, it’s state can be changed if it is a mutable object.
Immutable Objects : These are of in-built types like int, float, bool, string, unicode, tuple. In simple words, an immutable object can’t be changed after it is created.
To summarise the difference, mutable objects can change their state or contents and immutable objects can’t change their state or content.
Tuples are immutable i.e the value cannot be changed. So, Option D is correct.