Multiple Return Values in Python
Python has built-in support for multiple return values. This feature is often used in idiomatic Python, for example, to return both result and error values from a function.
To run the program, save it as multiple_return_values.py
and use python
:
In Python, functions can naturally return multiple values as tuples. The (int, int)
notation isn’t necessary as Python is dynamically typed.
The main()
function isn’t required in Python, but it’s a common convention to use it as the entry point of the script.
The ability to ignore certain return values using _
is a common Python idiom, similar to the blank identifier in other languages.
Accepting a variable number of arguments is another nice feature of Python functions; we’ll look at this next.