Unpack Tuples
Unpack Tuples
Unpacking is the process of assigning the tuple items as values to variables.
Example:
Output:
Here, the number of list items is equal to the number of variables.
But what if we have more number of items then the variables?
You can add an * to one of the variables and depending upon the position of variable and number of items, python matches variables to values and assigns it to the variables.
Example 1:
Output:
Example 2:
Output:
Example 3:
Output: