The Concept of Mutability in Python


Understand which objects can be changed (mutable) and which cannot (immutable).

Source Code

# Lists are mutable
my_list = [1, 2, 3]
my_list[0] = 99

# Strings are immutable
my_string = "hello"
# my_string[0] = "H"  # Raises TypeError
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments