Tuples
A tuple is like a sealed pack of stickers.
The order stays. The items stay.
You cannot add or remove after you make it.
Tuples use parentheses and commas.
Creating a tuple
Write items inside ( and ).
A one-item tuple needs a comma. That is easy to forget.
Reading items
Indexing works like lists.
Slicing works like lists too.
You can read. You cannot rewrite an index.
Why use a tuple?
Use a tuple when the group should not change.
A point with x and y
Days of the week
A fixed pair like (name, score)
A safe return of many values from a function
Unpacking
You can pour tuple items into separate names.
Like opening a pack and putting each sticker in its own spot.
Tuples vs lists
Lists change. Tuples stay put.
Lists use []. Tuples use ().
If you need to sort or append a lot, use a list.
If the group is a fixed fact, use a tuple.
Converting
Use tuple() and list() to switch shapes.
Tip: Reach for a tuple when the collection is a finished fact, not a growing bag.
Test yourself
Three quick questions made just for this lesson. Earn 10 XP per correct answer.