wiz-icon
MyQuestionIcon
MyQuestionIcon
1
You visited us 1 times! Enjoying our articles? Unlock Full Access!
Question

Using an example, show how a function in Python can return multiple values.

Open in App
Solution

Program:
def myfun():
return 1, 2, 3
a, b, c = myfun()
print(a)

print(b)
print(c)


OUTPUT:
1
2
3


NOTE: Although it looks like 'myfun()' returns multiple values, but actually a tuple is being created here. It is the comma that forms a tuple, not the parentheses, unless it is absolutely required there, such as in the case of a blank tuple.

flag
Suggest Corrections
thumbs-up
1
Join BYJU'S Learning Program
similar_icon
Related Videos
thumbnail
lock
Introduction
MATHEMATICS
Watch in App
Join BYJU'S Learning Program
CrossIcon