Interview Question

What is mutable and immutable?

Mutable objects can change in place; immutable objects require a new value.

💡 Concept ✅ Quick Revision 🐍 Python

Answer

Mutability describes whether an object’s value can change after creation. • Lists, dictionaries, and sets are mutable. • Strings, tuples, numbers, and frozensets are immutable. • A tuple can contain a mutable object even though the tuple itself is immutable.

💡 Simple Example

items = [1, 2] items.append(3) text = 'py' text = text + 'thon' print(items, text)

Output

[1, 2, 3] python

⚡ Quick Revision

Mutable objects can change in place; immutable objects require a new value.