Tuples
Like this video? Get new free AI lessons on YouTube.
SubscribeA tuple is like a list, but immutable: once created it cannot be changed. Tuples are perfect for fixed groups of values that belong together, like a coordinate (x, y) or an RGB color.
What You'll Learn
- Creating tuples and accessing items
- Why immutability is useful
- Unpacking a tuple into variables
Creating Tuples
Tuples use parentheses. A single-item tuple needs a trailing comma:
Immutable on Purpose
Trying to change a tuple raises an error. That is a feature: it protects data that should not change, and it lets tuples be used as dictionary keys (you will see this soon).
Unpacking
You can pull a tuple apart into separate variables in one line. This is clean and very common:
Functions Return Tuples
When a function gives back more than one value, it is returning a tuple. Unpacking makes it readable:
Key Takeaways
- Tuples use parentheses:
(1, 2, 3)and cannot be changed - Access items with the same indexing as lists
- Unpack with
a, b = my_tuple - Use tuples for fixed data and for returning several values at once
Quiz
Up next · Lesson 18 of 24
Project: To-Do List Manager
1 min read
17 of 24 lessons done

Ask Byte about this lesson
A private chat about this lesson. Byte has read the whole lesson, answers in seconds, and shows the section each answer comes from. Ask follow-ups in any language.
Questions & Answers
Public questions about this lesson. The AI Tutor answers right away in your language, the FreeAcademy team checks answers, and every learner can read them.

