How to use one of the tuple return values from a function in a nested elif in python?

Question:

def test():
    return(True, '123')

items = test()

I need to use return value of items[0] as a test condition in a nested else if statement. How do I do it at the else if statement?

Asked By: LohTC

||

Answers:

if items[0] ...:
  ...

Just refer to it as items[0], it has the same indexing manner as a list.

Answered By: DialFrost

Other comments/answers have pointed out the obvious, however, it would also be valid to say something like:

condition, value = test()

and to use:

if condition: ...
Answered By: Cresht

this syntax works without requiring a handle

if a > b:
do task
elif test()[0]:
do task

Answered By: LohTC