Sequence unpacking

To create a tuple, we simply create a variable and assign items to it, separated by commas. The term for this is packing a tuple, because the data is packed into the tuple, all wrapped up and ready to go. To remove items from a tuple, you simply unpack it, as shown in the following screenshot:

Unpacking a tuple

In line 60, the tuple is packed with a sequence of numbers, and in line 61, the items in the tuple (the numbers) are unpacked and assigned to individual variables. Lines 62-65 demonstrate that each number has been assigned to separate variables.

Line 66 shows the same thing, except the tuple parentheses, have been ...

Get Learn Programming in Python with Cody Jackson now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.