O'Reilly logo

Python Essentials by Steven F. Lott

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required