Mutable vs Immutable Objects

In short: A mutable object can be changed after it's created; an immutable object cannot. In Python, lists and dictionaries are mutable while strings, numbers, and tuples are immutable—a distinction behind interview questions on copying, hashing, and default arguments.

A mutable object can be changed after it's created, and an immutable object can't.

For example, lists are mutable in Python:

int_list = [4, 9] int_list[0] = 1 # int_list is now [1, 9]

And tuples are immutable:

int_tuple = (4, 9) int_tuple[0] = 1 # Raises: TypeError: 'tuple' object does not support item assignment

Strings can be mutable or immutable depending on the language.

Strings are immutable in Python:

test_string = 'mutable?' test_string[7] = '!' # Raises: TypeError: 'str' object does not support item assignment

But in some other languages, like Ruby, strings are mutable:

test_string = 'mutable?' test_string[7] = '!' # test_string is now 'mutable!'

Mutable objects are nice because you can make changes in-place, without allocating a new object. But be careful—whenever you make an in-place change to an object, all references to that object will now reflect the change.

Frequently Asked Questions

What's the difference between mutable and immutable objects?

Mutable objects can be modified in place after creation; immutable objects cannot—any 'change' creates a new object instead.

Which Python types are immutable?

Numbers (int, float), strings, tuples, frozensets, and booleans are immutable. Lists, dictionaries, and sets are mutable.

Why does mutability matter in interviews?

It explains gotchas like shared references, mutable default arguments, and why only immutable (hashable) objects can be used as dictionary keys or set elements.

Last updated: June 17, 2026

What's next?

If you're ready to start applying these concepts to some problems, check out our mock coding interview questions.

They mimic a real interview by offering hints when you're stuck or you're missing an optimization.

Try some questions now

. . .