0 votes
in Python by
What is tuple unpacking? Why is it important?

1 Answer

0 votes
by
The short answer: Unpacking refers to the practice of assigning elements of a tuple to multiple variables. You use the * operator to assign elements of an unpacking assignment to assign it a value.

With unpacking, you can swap variables without using a temporary variable. For example:

x = 20

y = 30

print(f'x={x}, y={y}')

x, y = y, x

print(f'x={x}, y={y}')

Output:

x=20, y=30

x=30, y=20
...