Python has a parameter unpacking package, which is cool. Therefore, although you can only return one value, if it is a tuple, you can unpack it automatically:
>>> def foo():
... return 1, 2, 3, 4
>>> foo()
(1, 2, 3, 4)
>>> a, b, c, d = foo()
>>> a
1
>>> b
2
>>> c
3
>>> d
4
In Python 3, you have more advanced features:
>>> a, *b = foo()
>>> a
1
>>> b
[2, 3, 4]
>>> *a, b = foo()
>>> a
[1, 2, 3]
>>> b
4
>>> a, *b, c = foo()
>>> a
1
>>> b
[2, 3]
>>> c
4
But this does not work in Python 2.
source
share