jeudi 21 novembre 2019

if result of argument satisfies a condition, how to return result immediately without having to restate the argument

how to return a result of an argument that satisfies a condition without having to rewrite the argument in the return function.

e.g. (Long method)

if a+b > c:
    return a+b

is there a shorter syntax in the likes of-

if a+b > c
    return ans

(where in this case ans == a+b)

usually, the argument is much more complex than just a + b so it would save a lot of trouble retyping the entire argument

Aucun commentaire:

Enregistrer un commentaire