Sometimes, we want to return multiple values from a function with Python.
In this article, we’ll look at how to return multiple values from a function with Python.
How to return multiple values from a function with Python?
To return multiple values from a function with Python, we can return a tuple.
For instance, we write
def f():
return True, False
x, y = f()
to define the f function that returns a tuple with True and False in it.
And then we unpack the returned values returned from f with
x, y = f()
Therefore x is True and y is False.
Conclusion
To return multiple values from a function with Python, we can return a tuple.