Using the list collection

Python's list collection is its built-in mutable sequence. We can create list objects easily using a literal display that simply provides expressions enclosed in []. It looks like this:

fib_list = [1, 1, 3, 5, 8]

As with tuples, the items are identified by their position in the list collection. Positions are numbered from the left starting from zero. Positions are also numbered from the right, using negative numbers. The last value in a list is at position -1, the next-to-last value at position -2.

Tip

Index values begin with zero. Index position 0 is the first item. Index values can be done in reverse with negative numbers. Index position -1 is the last item.

We can also create lists using the list() function. This will convert ...

Get Python Essentials now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.