Sequences are ordered sets of objects indexed by non-negative integers. Sequences include string, list, tuple, and range objects. Lists and tuples are sequences of arbitrary objects, whereas strings are sequences of characters. However, string, tuple, and range objects are immutable, whereas, the list object is mutable. All sequence types have a number of operations in common. Note that, for the immutable types, any operation will only return a value rather than actually change the value.
For all sequences, the indexing and slicing operators apply as described in the previous chapter. The string and list data types were discussed in detail in Chapter 1, Python Objects, Types, and Expressions. Here, we present some of the important methods and operations that are common to all of the sequence types (string, list, tuple, and range objects).
All sequences have the following...