FiveBlue
FiveBlue

Reputation: 35

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

Upvotes: 0

Views: 2032

Answers (2)

user2668284
user2668284

Reputation:

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)

Upvotes: 3

Jussi Nurminen
Jussi Nurminen

Reputation: 2408

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

Upvotes: 5

Related Questions