When it comes to best practices on conditionals, which of the following examples is recommended?
def sum(arg1,arg2):
if arg1>3:
return
else:
return arg1+agr2
or
def sum(arg1,arg2):
if arg1<3:
return arg1+agr2
else:
return
Thanks in advance!
Consider using a ternary expression:
As an addendum, if one of the cases is unexpected or undesirable, I like to follow the guard pattern, which involves checking for these cases first before performing your normal logic.
For example,