Great question, there are three possible answers to this question in my mind.
- You could give the function addresses (or pass by reference) of variable which you then set in the function
- You could create a Tuple class that holds multiple values, initialize the class with a temporary object, set the values you wish to return to the object, and return the object.
- Finally, I think the simplest solution would be to return multiple values in one return statement, (supported in python, not supported in C++), this is the best solution in my opinion because if the function output is printed, it prints all three returns as if they are in a three dimensional graph. (x, y, z). Here is some example code...
def f():
val1 = 1
val2 = 2.7
val3 = "happy"
return val1, val2, val3
num1 = f()
print(num1)
The printout would be: "
(1, 2.7, 'happy')
"
this example shows that the return type doesn't have to be the same for all of the elements