How to return tuple from function in Python

3 Answers

0 votes
def function():
    return (8934, 'Tom')

tpl = function()

print(tpl)
print(type(tpl))



'''
run:

(8934, 'Tom')
<class 'tuple'>

'''

 



answered Jan 9, 2021 by avibootz
0 votes
def function(id, name):
    tpl = (id, name)

    return tpl

tpl = function(9832, 'Emma')

print(tpl)
print(type(tpl))



'''
run:

(9832, 'Emma')
<class 'tuple'>

'''

 



answered Jan 9, 2021 by avibootz
0 votes
def function(id, name):
    yield (id[0], name[0])
    yield (id[1], name[1])

tpl1, tpl2 = function([3457, 1098], ['Tom', 'Emma'])

print(tpl1)
print(type(tpl1))

print(tpl2)
print(type(tpl2))



'''
run:

(3457, 'Tom')
<class 'tuple'>
(1098, 'Emma')
<class 'tuple'>

'''

 



answered Jan 9, 2021 by avibootz

Related questions

1 answer 96 views
1 answer 151 views
1 answer 176 views
1 answer 124 views
2 answers 131 views
2 answers 146 views
1 answer 128 views
...