programming-examples/python/Tuple/Python program to unpack a tuple in several variables.py

8 lines
221 B
Python
Raw Permalink Normal View History

2019-11-15 12:59:38 +01:00
#create a tuple
tuplex = 4, 8, 3
print(tuplex)
n1, n2, n3 = tuplex
#unpack a tuple in variables
print(n1 + n2 + n3)
#the number of variables must be equal to the number of items of the tuple
n1, n2, n3, n4 = tuplex