Understanding Mutable vs Immutable Types in Python


Source Code

# Mutable example
my_list = [1, 2, 3]
my_list[0] = 99
print(my_list)  # [99, 2, 3]

# Immutable example
my_string = "hello"
# my_string[0] = "H"  # Would raise an error because strings are immutable
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments