liveBook · Manning

Tuple unpacking

Tuple unpacking is assigning the elements of an iterable to multiple corresponding targets in a single operation.

How 3 Manning books explain it

Python How-To

Unpacking is the technique of retrieving the individual items of an iterable and assigning them to corresponding variables.

How it is used
Uses unpacking to extract iterable items into named variables in assignments, loops, and function calls.
How deep it goes
Explains one-to-one, starred, underscore, and nested unpacking through examples and an exercise.
Examples
Uses task records, numbered prime values, returned statistics, and a nested-list exercise.
What you can do after
Apply it in Python to name iterable items, handle unwanted values, and unpack function results.

Read how Python How-To explains tuple unpacking →

Pandas Workout: 200 exercises to make you a stronger data analyst

Tuple unpacking assigns the elements of an iterable to multiple variables in one assignment.

How it is used
Uses filename metadata to create city and state fields while loading multiple CSV files into pandas DataFrames.
How deep it goes
Explains the two-element list returned by split and applies direct assignment, without extending into broader unpacking patterns.
Examples
Uses `new+york,ny.csv` to extract city and state before normalizing and assigning them as DataFrame columns.
What you can do after
Apply it in Python to capture multiple values from a split filename during batch CSV loading.

Read how Pandas Workout: 200 exercises to make you a stronger data analyst explains tuple unpacking →

Python Workout, Second Edition

Unpacking is a Python assignment operation that extracts elements from an iterable into separate targets.

How it is used
Uses unpacking to capture related values from enumerate, split input, and comprehension iterators.
How deep it goes
Demonstrates direct assignment in loops, functions, and comprehensions, while leaving advanced pattern matching mostly unelaborated.
Examples
Uses alphabet iteration, calculator input parsing, and alphabet-to-number dictionary comprehensions.
What you can do after
Apply unpacking via enumerate and str.split to write compact loops, parsers, and comprehensions.

Read how Python Workout, Second Edition explains tuple unpacking →

Also covered in

What to know first

Related concepts

Questions about tuple unpacking

What is tuple unpacking?

Tuple unpacking is assigning the elements of an iterable to multiple corresponding targets in a single operation.

Which Manning books explain tuple unpacking?

Python How-To, Pandas Workout: 200 exercises to make you a stronger data analyst and Python Workout, Second Edition.

What should I know before learning tuple unpacking?

Manning books that teach tuple unpacking usually introduce tuple, list, loop and Map first.

These guides are generated from the text of Manning books by Manning's knowledge graph and link to the sections they draw on. The full books are available on liveBook and at manning.com.