Returns multiple values
Can a function return multiple values? The answer is yes.
For example, in the game often need to move from one point to another point, give the coordinates, displacements and angles, you can calculate the new coordinates:
# The Math package provides the sin () and cos () functions, which we first refer to with import:
Import mathdef Move (x, y, step, Angle): NX = x + step * math.cos (angle) NY = y-step * Math.sin (angle) return NX, Nyprint (Move (+, +, MATH.PI/6))
But this is just an illusion, and the Python function returns a single value:
>>> r = Move (+, +, MATH.PI/6)
>>> Print R
(151.96152422706632, 70.0)
Prints the returned result with print, the original return value is a tuple!
However, in syntax, the return of a tuple can omit parentheses, and multiple variables can receive a tuple at the same time, by the location of the corresponding value, so the Python function returns a multi-value is actually returned a tuple, but it is more convenient to write.
Python function returns multi-value