What is the difference between a mutable and an immutable data type in Python?
What is the difference between a mutable and an immutable data type in Python?
What is the difference between a mutable and an immutable data type in Python?
solveurit24@gmail.com Changed status to publish February 13, 2025
- Mutable: Objects whose values can be changed after creation (e.g.,
list,dict,set). - Immutable: Objects whose values cannot be changed after creation (e.g.,
int,float,string,tuple).
Example:
# Mutable (list)
my_list = [1, 2, 3]
my_list[0] = 100 # Can modify the list
# Immutable (tuple)
my_tuple = (1, 2, 3)
my_tuple[0] = 100 # Raises TypeError
solveurit24@gmail.com Changed status to publish February 13, 2025