Lists
Lists have many different uses when coding, and many different operations can be performed on lists, thanks to Python. In this chapter, you will only learn about some of the many uses of lists.
Note
If you wish to learn more about lists, the Python documentation is very detailed and can be found at https://docs.python.org/3/tutorial/datastructures.html?highlight=lists#more-on-lists.
First, some facts about Python lists: Python lists are mutable. This means that the data in a list can be changed around. Items can be added or removed using functions that act directly on the list. Also, the items in a list can be mixed together. Numbers, floats, and strings can all go together in the same list.
Parts of a list
Lists, like other kinds of data, are assigned to a variable. Then, the list items are placed in [ ]
:
In your Python shell, type the following three lists, one on each line:
fruit = ['apple', 'banana', 'kiwi', 'dragonfruit'] years = [2012, 2013, 2014, 2015] students_in_class = [30, ...