Sequence Types - Intro¶
Contents¶
Indices and tables¶
Definition¶
In Python, a sequence type is a container type that stores an ordered set of items indexed by numbers. If the sequence is of length n, then the index can run from 0 to n-1 to access items in the forward direction and -1 to -n to access items in the reverse direction.
Note
At first negative indices may seem unusual, but, they are actually quite useful.
Items in a sequence are extracted using the item access operator []
.
Sequences come in both immutable and mutable types. For immutable types, the collection of objects directly referenced as items in the sequence, can’t change, even if the value of the referenced object does. What is important to understand is that the reference is immutable, not the content of the referenced item.
Tip
In addition to the sequence types described here, the collections
module holds additional container types which might be useful in your travels. However, they will not be discussed here.
The different sequence types will be described first, and then operations on them will follow at the end.