Chapter 6
Lists
Meet Lists
A
Imagine keeping three places you would like to visit:
This program works, but the variable names are doing too much work. Adding a fourth place means inventing another name. Treating all the places as one group is awkward.
A
The square brackets mark the beginning and end of the list. Commas separate its items. The list itself is one value, so one variable can refer to the complete collection.
Order is part of the list
Python keeps list items in the order you write them:
That order can carry meaning. A packing list, a reading list, and a set of project steps are all useful examples of ordered collections.
Lists can hold values of different
An empty pair of brackets creates an empty list:
An empty list is still a list. It simply contains no items yet.
Which value is a Python list?
A list gives several related values one ordered home. Next, you will create lists of your own and inspect what Python stores in them.