O'Reilly logo

A Practical Guide to Linux® Commands, Editors, and Shell Programming, Third Edition by Mark G. Sobell

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

Lists

A Python list is an object that comprises one or more elements; it is similar to an array in C or Java. Lists are ordered and use zero-based indexing (i.e., the first element of a list is numbered zero). A list is called iterable because it can provide successive elements on each iteration through a looping control structure such as for; see page 572 for a discussion.

This section shows one way to instantiate (create) a list. The following commands instantiate and display a list named a that holds four values:

>>> a = ['bb', 'dd', 'zz', 'rr']>>> a['bb', 'dd', 'zz', 'rr']

Indexes

You can access an element of a list by specifying its index (remember—the first element of a list is numbered zero). The first of the following commands displays ...

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