Python sequence types are used to represent ordered collections of objects. They are classified into mutable and immutable sequence types. Here, we will only discuss
lists (mutable) and
strings (both immutable). Other sequence types are mentioned at the end of this section.
The following example shows how to construct a list in Python and assign it to a variable:
numbers = [0, 1.2, 234259399992, 4+3j]
Individual entries in the list are accessed with index notation as follows:
Notice that indexing always starts with
0. Negative indices are allowed and they represent positions starting at the end of the list. For example,
numbers[-1] is the last entry,
numbers[-2] is the next-to-last entry, and so forth. ...