Robotics & Artificial Intelligence
Is it possible to return more than one statement to the main function? Justify.
Python Functions
1 Like
Answer
Yes, it is possible to return more than one value from a function to the main program in Python. Unlike other programming languages, Python allows a function to return multiple values using a single return statement, where the values are separated by commas. These multiple values are automatically packed into a tuple and returned to the caller.
For example,
def Sum(a, b):
return a+5, b*5
# main program
result = Sum(4, 5)
print(result)
Output: (9, 25)
Here, the function Sum() returns two values which are received as a tuple in the main program.
Answered By
3 Likes