Tuples
Python · Unit 8: Tuples and sets
- Full plan
- Python
- 10 exercises
A tuple holds several values together, like a list, but it goes inside parentheses ().
You read it just like a list: indexes from 0, slices, len() and in.
point = (3, 5)
print(point[0])
print(len(point))
print(point)Prints
3 2 (3, 5)
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 line creates a tuple with the row and seat on your ticket?
2. Predict the output
What does this code print?
3. Predict the output
What does this code print?
4. Complete the code
Complete it so it says whether today is a weekend day.
5. Find the bug
This program should change the appointment's minutes to 45. Which line has the bug?
6. Multiple choice
If
t = (5, 8, 2), which of these lines gives an error?7. Predict the output
What does this code print?
8. Complete the code
Complete it so
prizesis a tuple with a single prize.9. Put the lines in order
Put in order the function that returns the names of the sold-out products. Each product is a tuple
(name, units).10. Predict the output
You've already used
items()with dictionaries. What does it print with a single name in thefor?
It opens in your browser. This lesson is part of the full plan; the first unit of each course is free.