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 use the return
statement with values separated by commas.
For instance, we write:
def foo():
return True, False
x, y = foo()
print(x)
print(y)
to define the foo
function that returns True
and False
.
And then we call foo
and assign the returned values to x
and y
.
Therefore, we see:
True
False
printed.
Conclusion
To return multiple values from a function with Python, we can use the return
statement with values separated by commas.