Introduction To Computation and Programming Using Python, Revised - Guttag, John v..83
Introduction To Computation and Programming Using Python, Revised - Guttag, John v..83
5.4
Type of elements
Examples of literals
Mutable
str
characters
No
tuple
any type
No
list
any type
Yes
One advantage of tuples is that because they are immutable, aliasing is never a
worry. Another advantage of their being immutable is that tuples, unlike lists,
can be used as keys in dictionaries, as we will see in the next section.
Since strings can contain only characters, they are considerably less versatile
than tuples or lists. On the other hand, when you are working with a string of
characters there are many built-in methods that make life easy. Figure 5.8
contains short descriptions of a few of them. Keep in mind that since strings are
immutable these all return values and have no side effect.