CBSE Class 12 Computer Science Question 62 of 103

Working with Functions — Question 9

Back to all questions
9
Question

Question 9

Can a function return multiple values ? How ?

Answer

Yes, a function can return multiple values. To return multiple values from a function, we have to ensure following things :

1. The return statement inside a function body should be of the form :

return <value1/variable1/expression1>,<value2/variable2/expression2>,....

2. The function call statement should receive or use the returned values in one of the following ways :

(a) Either receive the returned values in form a tuple variable.

(b) Or we can directly unpack the received values of tuple by specifying the same number of variables on the left-hand side of the assignment in function call.