Slices
Python · Unit 5: Lists
- Full plan
- Python
- 10 exercises
items[a:b] takes a piece: from index a up to just before b. As in range, the end is left out.
The piece is a new list.
nums = [10, 20, 30, 40, 50]
print(nums[1:4])Prints
[20, 30, 40]
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. Predict the output
What does this code print?
2. Multiple choice
What is the difference between
nums[2]andnums[2:3]?3. Complete the code
Complete it to keep 20, 30 and 40.
4. Predict the output
The tournament points run from highest to lowest. What does it print?
5. Complete the code
Complete it to print the last three temperatures.
6. Multiple choice
After this code, what does
rowhold?7. Predict the output
What does this code print?
8. Put the lines in order
Put the lines in order to print the countdown 3, 2, 1.
9. Find the bug
The race times run from fastest to slowest. The program should print the top three. Which line has the error?
10. Predict the output
Ava is already at the register. What does it print?
It opens in your browser. This lesson is part of the full plan; the first unit of each course is free.