pythonmultiple-return-values

Multiple return values, just one 'if' checking functions return


What return value(s) does Python check when a function returns multiple values, but there is only one 'if' checking the function's result?

Thank you for your time.

def func1(args):
    return pass, data

def func2
   if func1(args):
       ...
   else 
       raise Exception ...

Solution

  • When you return multiple values, you're actually returning a tuple containing each of those values.

    Your if test will return True regardless of the values (even if they are both None)