How to unpack the tuple values into separate variables in Python

3 Answers

0 votes
tpl = (274, 3.14, "python")
i, f, s = tpl

print(i)      
print(f)      
print(s)     



'''
run:
 
274
3.14
python

'''

 



answered Feb 10, 2020 by avibootz
0 votes
tpl = (274, "python", "c++", "java", 3.14)

i, *s, f = tpl

print(i)      
print(s)      
print(f)     



'''
run:
 
274
['python', 'c++', 'java']
3.14

'''

 



answered Feb 10, 2020 by avibootz
0 votes
tpl = (274, "python", "c++", "java", 3.14)

c, b, *c = tpl

print(a)      
print(b)      
print(c)     



'''
run:
 
274
python
['c++', 'java', 3.14]

'''

 



answered Feb 10, 2020 by avibootz

Related questions

2 answers 266 views
1 answer 132 views
1 answer 175 views
2 answers 157 views
3 answers 212 views
...