mardi 5 mai 2015

Assign within if statement Python

Is there a simpler alternative than

res = returns_value_or_none(arg)
if res:
    do_something_with(res)

or

if returns_value_or_none(arg):
    do_something_with(returns_value_or_none(arg))

One which combines the assignment and if conditional into one statement?

Aucun commentaire:

Enregistrer un commentaire