title: Python: is it possible to return a variable amount of variables as requested?
body: <p>I'd like to return either one or two variables for a function in python(3.x). Ideally, that would depend on amount of returned variables requested by user on function call. For example, the <code>max()</code> function returns by default the max value and can return the argmax. In python, that would look something like:</p>
  
  <pre><code>maximum = max(array)
  maximum, index = max(array)
  </code></pre>
  
  <p>Im currently solving this with an extra argument return_arg:</p>
  
  <pre><code>import numpy as np
  
  def my_max(array, return_arg=False):
     maximum = np.max(array)
  
     if return_arg:
        index = np.argmax(array)
        return maximum, index
     else:
        return maximum
  </code></pre>
  
  <p>This way, the first block of code would look like this:</p>
  
  <pre><code>maximum = my_max(array)
  maximum, index = my_max(array, return_arg=True)
  </code></pre>
  
  <p>Is there a way to avoid the extra argument? Maybe testing for how many vaules the user is expecting? I know you can return a tuple and unpack it when calling it (that's what I'm doing).</p>
  
  <p>Asume the actual function I'm doing this in is one where this behaviour makes sense.</p>