I always returns directly when it does not impact.
I did not find reference about that, but here is my vision
Because some time you could have to do stuff like
for spam in bacon:
if spam == egg:
return spam
But if you want to avoid returning within the if
statement you will have to do:
return_value = None
from spam in bacon:
if spam == egg:
return_value = spam
break
return return_value
Which result to the exact same result & execution but only add 3 non relevant lines so I finally think when this happen I always use the same rule: return directly.
The thing is to not go too deep with for
/ if
/ return
, but that is not really the question here.