Concept Flow - Tuple unpacking
Create tuple with values
Assign tuple to variables
Unpack values into variables
Use variables separately
Tuple unpacking takes a tuple and assigns each value to a separate variable in one step.
point = (3, 7) x, y = point print(x) print(y)
| Step | Action | Evaluation | Result |
|---|---|---|---|
| 1 | Create tuple 'point' | point = (3, 7) | point holds (3, 7) |
| 2 | Unpack tuple into x and y | x, y = point | x = 3, y = 7 |
| 3 | Print x | print(x) | 3 |
| 4 | Print y | print(y) | 7 |
| 5 | End | No more code | Execution stops |
| Variable | Start | After Step 1 | After Step 2 | Final |
|---|---|---|---|---|
| point | undefined | (3, 7) | (3, 7) | (3, 7) |
| x | undefined | undefined | 3 | 3 |
| y | undefined | undefined | 7 | 7 |
Tuple unpacking syntax: x, y = (value1, value2) Assigns each tuple element to variables in order. Number of variables must match tuple size. Useful for clean, readable code when working with tuples.