CMSC 201

Lab 5: Loops

Lists

What are they?

A list is a collection of items that can be referenced by the same name.
Each element of the list can be accessed by its position.

How do I use them?

In python, this is how you initialize lists!

list1 = []#A new empty list
list2 = [1, 2, 3, "jello"]#A new non-empty list

How to access each element in a list?

Use indexes!
item = list[i] returns the item at index i

list2 = [1, 2, 3, "jello"]
print(list2[3])