Need every field from a short tuple? Assign them in one line instead of indexing each position separately: `task_id, task_title, task_urgency = task`. Each item goes to the corresponding variable. This is tuple unpacking: the reverse of packing several items into a tuple. The same technique works with lists and other iterables. section 4.4 section 4.4.1
task = (1001, "Laundry", 5)
task_id, task_title, task_urgency = task
print(task_id, task_title, task_urgency)
# output: 1001 Laundry 5
user_data = ("python_user", 35, "male")
username, age, gender = user_data
print(username, age, gender)
# output: python_user 35 male
Compare the tuple fields with the variables on the left: their positions match, and one assignment replaces several indexed assignments. section 4.4.1
For one-to-one unpacking, provide a variable for each item. Parentheses are optional on either side of a tuple assignment: `x, y = 90, 20` works as well as `x, y = (90, 20)`. Keep multiple assignments together when the variables are closely related; separate unrelated assignments for readability. section 4.4.1
Use only the fields you need
Suppose `task` is `(1001, "Laundry", "Wash clothes", "completed")`. Write `task_id, _, _, task_status = task` when only the ID and status matter. Underscores conventionally mark unwanted values; they are still valid variable names, so repeating `_` overwrites its earlier value. To skip the middle as a group, use `task_id, *_, task_status = task`. section 4.4.3
Unpack values produced elsewhere
A function that appears to return two values returns one tuple. Assign its components directly: `m_mean, m_std = generate_stats(measures)`. Likewise, `for num_pos, num in enumerate(prime_numbers, start=1):` assigns the position and number on each iteration. section 6.2.3 section 1.4.1
The assignment pattern can also follow nested data. For `[1, (2, 3), 4]`, write `a, (b, c), d = [1, (2, 3), 4]` to extract all four numbers in one line. Choose a pattern that makes the data’s shape and the values you intend to use clear. section 4.4.5 section 4.4.4


