Book Image

Python Essentials

By : Steven F. Lott
Book Image

Python Essentials

By: Steven F. Lott

Overview of this book

Table of Contents (22 chapters)
Python Essentials
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

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 many kinds of collections into list objects. Used without arguments, list() creates an empty list just like []. Since the list() function is so versatile at converting collections into list objects, we'll use it much more in later chapters.

We...