O'Reilly logo

IPython Notebook Essentials by L. Felipe Martins

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

Sequence types

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 tuples and strings (both immutable). Other sequence types are mentioned at the end of this section.

Lists

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:

numbers[2]

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

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