Python Learning Series · @onlysamarrr · Day 16 / 30
Day 16 teaches tuples. A tuple is like a list, but it is immutable: once created it cannot be changed. That makes it usable as a dictionary key and slightly faster than a list.
Phase: Intermediate · Reels: 76/450 – 80/450
Day 16 teaches tuples. A tuple is like a list, but it is immutable: once created it cannot be changed. That makes it usable as a dictionary key and slightly faster than a list.
point = (3, 4) print(point, type(point)) print(type((5))) print(type((5,))) a, b = 1, 2 a, b = b, a print(a, b) first, *rest = [1, 2, 3, 4] print(first, rest)
(3, 4) <class 'tuple'> <class 'int'> <class 'tuple'> 2 1 1 [2, 3, 4]
Coordinates, RGB colours and database rows are often tuples, because they should not change by accident.
Select (tick) an option, then tap Check answer to see instantly whether your answer is right or wrong, with an explanation. You can change your answer and check again.
Q1. What is type((5))?
Q2. What is type((5,))?
Q3. What does a, b = b, a do?
| 76/450 | Concept | Tuple kya hai |
| 77/450 | Live demo | Packing aur unpacking |
| 78/450 | Common mistake | Single item tuple ki galti |
| 79/450 | Quiz | Quiz: values swap karo |
| 80/450 | Interview / real life | Interview: list vs tuple |