Python Practice › Tuple Programs › Program 7
Unpack a tuple into variables
Write a Python program to assign the values of a tuple to several variables and print them.
Input
(6, 7, 3)
Output
a, 6 b, 7 c, 3
Approach
- Tuple unpacking: one name per item.
Solution
a, b, c = (6, 7, 3)print("a,", a)print("b,", b)print("c,", c)Output
a, 6 b, 7 c, 3
Line by line
Line 1
The number of names must match the number of items.
Learn the concept
New to this topic? Read the lesson, then come back.
1 thought on “Unpack a tuple into variables”