KnowledgeBoat Logo

Computer Science

How is a mutable object different from an immutable object in Python ?

Identify one mutable object and one immutable object from the following:

(1, 2), [1, 2], {1:1, 2:2}, '123'

Python Funda

2 Likes

Answer

In Python, a mutable object can be changed after it is created (e.g., lists, dictionaries), while an immutable object cannot be modified after its creation (e.g., tuples, strings).

An example of a mutable object from the given options is [1, 2] (list) and {1:1, 2:2} (dictionary). [Write any one]

An example of an immutable object from the options is '123' (string) and (1, 2) (tuple). [Write any one]

Answered By

1 Like


Related Questions