a question about "return"

Tim Roberts timr at probo.com
Tue Jul 4 02:07:54 EDT 2006


"yaru22" <yaru22 at gmail.com> wrote:

>In one of the examples in the book I'm reading, it says:
>
>def __init__(self):
>    ...
>    ...
>    ...
>    return
>
>It has nothing after "return". I expected it to have some number like 0
>or 1.
>
>What does it mean to have nothing after return?

It means "the function is over, go back to the caller now".

>Why do we even include "return" if we are not putting any value after?

If it is the last statement in the function, then you are right, it serves
no purpose.  Some people include one for completeness -- a coding standard
that "all paths must have a return statement", for instance.
-- 
- Tim Roberts, timr at probo.com
  Providenza & Boekelheide, Inc.



More information about the Python-list mailing list