When I have multiple checks and the result of any successful check is a return statement, would it be more pythonic to use if or elif for the next checks?
i.e.
def test(a):
if a==1:
return 'hello'
if a==2:
return 'big'
if a==3:
return 'world'
return 'oops'
or
def test(a):
if a==1:
return 'hello'
elif a==2:
return 'big'
elif a==3:
return 'world'
else:
return 'oops'
Aucun commentaire:
Enregistrer un commentaire