Q. Differentiate between mutable and immutable objects in Python language with example.
Answer =
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. The type of the object is defined at the runtime and it can't be changed afterwards.
However, its state can be changed if it is a mutable object.
For example, int, float, bool, string, unicode, tuple are immutable objects in Python. In simple words, an immutable object can't be changed after it is created. Lists, dictionaries and sets are mutable types.
Post a Comment
You can help us by Clicking on ads. ^_^
Please do not send spam comment : )