Python sequences can either be mutable or immutable. Immutable sequences include strings and tuples whereas lists are mutable. After its creation, any element of an immutable sequence cannot be changed (replaced or deleted) whereas this is possible in case of mutable sequences. Immutable objects offer certain advantages: (usually) fixed and unchanged storage requirements, thread safety (since no one can change the sequence, all threads see the same thing), ease in handling multiple copies etc.
To test the immutability of strings, let's make a simple string:
strFruits='Apples, Oranges, Bananas, Coconuts, Lychee, Watermelon, Mangoes'
Let's try changing its first element:
strFruits[0]='a'
As you can see that we get a TypeError exception indicating that we cannot change this. Let's print the string:
print strFruits
No difference here!
Let's try the same thing with a tuple now:
tplFruits=('Apples','Oranges','Bananas','Coconuts','Lychee','Watermelon','Mangoes')
tplFruits[0]='Grapes!'
The same error! And also no change seen when we print this:
print tplFruits
Now with a list:
lstFruits=['Apples', 'Oranges', 'Bananas', 'Coconuts', 'Lychee', 'Watermelon', 'Mangoes']
print lstFruits
lstFruits[0]='Grapes'
No error! So we can change the contents of a list. Let's print it to see if we have, indeed, changed the list:
print lstFruits