A list holds many values in order
colors = ["red", "green", "blue"]
numbers = [3, 1, 4, 1, 5]
mixed = ["Ada", 36, True]
Positions start at 0, and -1 means the last item.
print(colors[0]) # red
print(colors[-1]) # blue
print(len(colors)) # 3
Lists can change
Unlike strings, a list is mutable — you can add, remove and reorder items in place.
numbers.append(9) # add to the end
numbers.remove(1) # remove the first 1
numbers.sort() # smallest to largest, in place
print(numbers)
Slicing works exactly like strings: colors[0:2] is ["red", "green"], and "a" in colors asks whether a value is in the list.
Reading the last item safely
Ask for an index that does not exist and Python raises IndexError — a list of 3 items has indexes 0, 1 and 2, and nothing else.