33
Question Question 33
In Python, strings are immutable while lists are mutable. What is the difference?
In Python, strings are immutable means that individual letter assignment for strings is not allowed. For example:
name='hello'
name[0] = 'p'The above Python code will cause an error as we are trying to assign some value to an individual letter of a string.
Lists are mutable in Python means that we can assign values to individual elements of a list. For example:
a = [1, 2, 3, 4, 5]
a[0] = 10The above Python code will work correctly without any errors as Lists are mutable in Python.