Summary on Sequences: Strings, Lists and Tuples

Till now, we have discussed different types of sequences viz. strings, lists and tuples. In 
many situations these sequences can be used interchangeably. Still, due their difference in 
behavior and ability, we may need to understand pros and cons of each of them and then 
to decide which one to use in a program. Here are few key points –
1. Strings are more limited compared to other sequences like lists and Tuples. 
Because, the elements in strings must be characters only. Moreover, strings are 
immutable. Hence, if we need to modify the characters in a sequence, it is better to 
go for a list of characters than a string. 
2. As lists are mutable, they are most common compared to tuples. But, in some 
situations as given below, tuples are preferable. 
a. When we have a return statement from a function, it is better to use tuples 
rather than lists.
b. When a dictionary key must be a sequence of elements, then we must use 
immutable type like strings and tuples
c. When a sequence of elements is being passed to a function as arguments, 
usage of tuples reduces unexpected behavior due to aliasing.
3. As tuples are immutable, the methods like sort() and reverse() cannot be applied on 
them. But, Python provides built-in functions sorted() and reversed() which will take 
a sequence as an argument and return a new sequence with modified results.
Posted on by