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

1.7k views Asked by At

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 ...
2

There are 2 answers

2
AudioBubble On BEST ANSWER

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)

0
Jussi Nurminen On

return a, b would return a tuple. The if statement will always evaluate, since non-empty tuples evaluate to True.