Coding Curriculum - Python

Immutability

There is one tiny difference though. A string is immutable whilst an array is not. This means that once a string is created, it cannot be changed. An array or list however can change. This might sound strange so let me give you an example.

array = ['a', 'b', 'c']
string = "abc"
# If we want to change the array, we can simply do the following:
array[0] = 'd' # now array = ['d', 'b', 'c']
# But we cannot do:
string[0] = 'a'  # ERROR
# If we want to change a string, we have to re-assign it:
string = "dbc"

Okay, this is enough for today, let's start coding!