</>
Topic 5 of 10
Theory

Lists

A list stores several values in order:

queue = ["Anna", "Tim", "Leia"]
print(queue[0], queue[-1])   # Anna Leia
print(len(queue))            # 3
queue.append("Max")          # add to the end
print(queue[1:3])            # slice: ['Tim', 'Leia']

Use in to check whether an item is there: "Anna" in queue. An empty list is false in a condition: if not queue:.

Last in line

Easy+10 XP

Return the name of the last person in the queue. If the queue is empty, return None.

last(["Anna", "Tim"]) → "Tim"
main.pyLoading Python…
Output
Press "Check" to run the tests