Tuples
A tuple is an ordered sequence of values that cannot be changed after you create it.
Used in 128 lessons of the course, from 00.01.
A tuple groups several values into one object. You write it with parentheses and commas: ("a", 1). What defines it is the commas, not the parentheses.
You read it like a list: by position, with t[0]. The difference is that it is immutable: you cannot change, add, or remove items. That makes it a good fit for data that belongs together and should not change, like a (text, module) pair.
A one-item tuple needs a trailing comma: (5,). Without the comma, (5) is just a number in parentheses.
In lesson 00.01 of the course, each value in the dictionary is a tuple:
"agent": ("A model that runs...", "Module 02")
The tuple keeps the definition and the module together, in a fixed order.
Reach for it when: you want to group a few values in a fixed order that should not change, like a pair or a multi-part result.
Examples
Common mistake
pair = ("agent", "Module 02")
pair[1] = "Module 03"Why: Tuples are immutable: you cannot assign to a position.
How to write it: Build a new tuple: pair = (pair[0], "Module 03"). If you need to change items, use a list.
Common mistake
one = ("hello")
print(type(one).__name__)
print(len(one))Why: Without a comma, the parentheses only group: `one` is a string, not a tuple.
How to write it: Add the trailing comma: ("hello",).
