"return" in def
Bruno Desthuilliers
bdesth.quelquechose at free.quelquepart.fr
Sun Dec 28 12:15:23 EST 2008
More information about the Python-list mailing list
Sun Dec 28 12:15:23 EST 2008
- Previous message (by thread): Apache/mod_python: Registering a request handler dynamically
- Next message (by thread): "return" in def
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
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.
- Previous message (by thread): Apache/mod_python: Registering a request handler dynamically
- Next message (by thread): "return" in def
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
More information about the Python-list mailing list