KnowledgeBoat Logo

Computer Science

Can a function return multiple values ? How ?

Python Functions

3 Likes

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.

Answered By

2 Likes


Related Questions