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?
Answers:
if items[0] ...:
...
Just refer to it as items[0]
, it has the same indexing manner as a list.
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: ...
this syntax works without requiring a handle
if a > b:
do task
elif test()[0]:
do task
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?
if items[0] ...:
...
Just refer to it as items[0]
, it has the same indexing manner as a list.
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: ...
this syntax works without requiring a handle
if a > b:
do task
elif test()[0]:
do task