"return" in def
Bruno Desthuilliers
bdesth.quelquechose at free.quelquepart.fr
Sun Dec 28 12:15:23 EST 2008
Roger a écrit :
>
> When I define a method I always include a return statement out of
> habit even if I don't return anything explicitly:
>
> def something():
> # do something
> return
>
> Is this pythonic or excessive?
If it's the last statement in the function body, it is indeed "excessive".
OTHO I sometimes end a function with an explicit "return None" when
there are branches with early returns, ie:
def func():
if some_condition:
return something
return None
to make really clear what happens - even if it _should_ be clear without
the last statement. IOW : use your own judgement.
More information about the Python-list
mailing list