mercredi 22 juillet 2015

Completing if statements with return

This is Python style question. If we have a function that can return early, making an else clause useless, e.g.

def f(x):
    if x > 0:
        return x
    else:
        return x + 1

is it more appropriate to just write

 def f(x):
    if x > 0:
        return x
    return x + 1

? I'm wondering what you all prefer. I like the latter, as it's more concise.

Aucun commentaire:

Enregistrer un commentaire