"return" in def
google at mrabarnett.plus.com
Sun Dec 28 20:25:19 CET 2008
Gerard Flanagan wrote:
> On Dec 28, 5:19 pm, Roger <rdcol... at gmail.com> wrote:
>> Hi Everyone,
>> 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
>> Is this pythonic or excessive? Is this an unnecessary affectation
>> that only adds clock ticks to my app and would I be better off
>> removing "returns" where nothing is returned or is it common practice
>> to have returns.
> It's not particularly excessive but it is uncommon. A nekkid return
> can sometimes be essential within a function body, so a non-essential
> nekkid return could be considered just noise.
If it's a function, ie the result is used by the caller, then explicitly
return with the value, even if it's None. On the other hand, if it's a
procedure, ie the result is always None and that result isn't used by
the caller, then don't use return, except for an early exit.
More information about the Python-list