Creating and indexing
Python · Unit 5: Lists
- Full plan
- Python
- 10 exercises
A list keeps several values in order. You write it inside brackets [], with commas between the values.
When you print it, Python shows the text in single quotes: it is the same thing.
fruits = ["fig", "plum", "kiwi"]
print(fruits)Prints
['fig', 'plum', 'kiwi']
The rest of the explanation is in the lesson, which is part of the full plan.
Exercises in this lesson
You do them in the app, which checks them on the spot and explains why.
1. Multiple choice
Which of these lines creates a list with three numbers?
2. Predict the output
What does this code print?
3. Complete the code
Complete it to print "Ava", the third one in line.
4. Predict the output
What does this code print?
5. Multiple choice
With this list, which of these gives "b"?
6. Predict the output
What does this code print?
7. Find the bug
This program should print the last person in line. Which line has the error?
8. Put the lines in order
Put the lines in order to print the last price using
len().9. Predict the output
If the person types 2, what does it print?
10. Find the case that fails
last(items)should return the last item, orNoneif the list is empty. Which call makes it fail?
It opens in your browser. This lesson is part of the full plan; the first unit of each course is free.