Does Python have any equivalent of nargout in MATLAB? I find nargout a very neat approach if we want to keep the number of return parameters flexible. Is there a way I can f
In Matlab, the number of output arguments is actually one of the inputs to a function. This is not the case in Python and so you have set up the function's interface to reflect this differently.
For example, here's a function that applies upper() to a group of strings, and the user can expect the the number of inputs equals the number of outputs. The syntax is also very similar to Matlab's.
>>> def var_returns_f(*args):
... return [str.upper() for str in args]
...
>>>
>>> a, b = var_returns_f('one', 'two')
>>>
>>> a
'ONE'
>>> b
'TWO'