Do these 3 things before closing this tab:
1Scan for outdated or missing drivers - takes under a minute2Repair Windows errors before they cause bigger problems3Fix the driver behind crashes, sound loss and screen glitchesAssign comma-separated names to the left of an iterable: x, y = (4, 9). Each name receives the value in the corresponding position. Without a starred target, the iterable must contain exactly as many items as there are names.
Unpack a tuple into variables
Put one target on the left for each tuple item:
point = (4, 9)
x, y = point
print(x) # 4
print(y) # 9
This is called sequence unpacking in the Python 3.11.16 tutorial. The operation assigns the values by position: the first item goes to x, the second to y. Multiple assignment combines tuple packing on the right with unpacking on the left.
Unpacking works with other iterables, too
The right-hand side does not have to be a tuple. Lists and other sequences can be unpacked the same way, and an iterable such as an iterator can be unpacked when its number of yielded values is known. The Python assignment reference describes assignment from iterables; the Functional Programming HOWTO discusses unpacking known-length iterators.
colors = ["red", "green"]
first, second = colors
first, second = iter(("red", "green"))
Match the number of values and targets
Without a starred target, the number of items must equal the number of targets. A mismatch raises ValueError:
Outdated Drivers Are Slowing You Down
One free scan finds every outdated or missing driver and matches the right update for your exact hardware.Free scan · exact hardware matchWindows Errors? Fix Them Before They Spread
Repair common Windows errors and clear accumulated junk for a smoother, more stable PC - no reinstall needed.Free scan · no reinstall#1 Best Overall
x, y = (1, 2, 3) # ValueError: too many values to unpack
x, y, z = (1, 2) # ValueError: not enough values to unpack
This exact-length rule is specified in the Python assignment reference. If the iterable’s length can vary, use a starred target for the values you do not want to name individually.
Use * to collect remaining values
A single starred target collects the items not assigned to targets before and after it. Python gives those collected items to the starred target as a list:
Rank #2
first, *middle, last = (10, 20, 30, 40)
# first is 10
# middle is [20, 30]
# last is 40
The iterable must still contain at least enough items for the non-starred targets. The starred list can be empty:
first, *middle, last = (10, 40)
# middle is []
The assignment reference documents the minimum-length rule and the list result.
Swap two values with multiple assignment
Unpacking lets you exchange two variables without a temporary variable:
left, right = right, left
The right-hand values are evaluated and packed before they are assigned to the left-hand targets. The Python tutorial describes multiple assignment as a combination of tuple packing and sequence unpacking.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Remember the comma in tuple syntax
Parentheses can group an expression, but a comma is what makes a tuple. For a one-item tuple, include the trailing comma:
single = (7,) # one-item tuple
not_a_tuple = (7) # integer 7
empty = () # empty tuple
The same singleton tuple can be written 7,. See the expressions reference and built-in types documentation for tuple syntax and behavior.
Recommended Free Tools
Best Value
When positional unpacking is hard to read
Unpacking is concise when positions are obvious, as with a coordinate pair. For heterogeneous records, however, names can be clearer than positions. The built-in types documentation notes that collections.namedtuple() may be more appropriate when named fields improve readability; ordinary tuples remain useful when positional access is clear.
Quick Recap
Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.




