Collections

Unpacking

Unpacking binds names from sequences and mappings concisely.

Unpacking binds multiple names from one iterable or mapping. It makes the structure of data visible at the point where values are introduced.

Source

point = (3, 4)
x, y = point
print(x, y)

Output

3 4
12345a*restb
Left-side names bind to right-side positions; `*rest` gathers the middle into a list.

Starred unpacking handles variable-length sequences by collecting the middle or remaining values. This keeps common head-tail patterns readable.

Source

first, *middle, last = [1, 2, 3, 4]
print(first, middle, last)

Output

1 [2, 3] 4

Dictionary unpacking with ** connects structured data to function calls. It is widely used in configuration, adapters, and code that bridges APIs.

Dictionary unpacking with ** connects structured data to function calls. It is widely used in configuration, adapters, and code that bridges APIs.

Source

def describe(name, language):
    print(name, language)

data = {"name": "Ada", "language": "Python"}
describe(**data)

Output

Ada Python

Notes

See also

Run the complete example

Example code

Expected output

3 4
1 [2, 3] 4
Ada Python

Execution time appears here after you run the example.