return statement in functions

Jp Calderone exarkun at
Tue Dec 23 20:50:11 CET 2003

On Tue, Dec 23, 2003 at 02:05:25PM -0500, hokieghal99 wrote:
> Jp Calderone wrote:
> [snip]
> >
> >  No.  "return new_dname" terminates execution of the function.  If you
> >  want many results, you need to collect them in a list and return the
> >  list, or use a generator.
> >
> >  Jp
> That's odd, it seems silly to terminate something that should be 
> recursive (os.walk) before it's finished being recursive. What's the 
> logic behind that idea?

  That is what "return" does.  Always.  :)  With no regard for context,
recursive or not (the implementation of os.walk itself may be recursive, or
it may not be, but I don't think it has any bearing on what "return" should
do, since the return isn't even inside the definition of os.walk!)

  If this is surprising, you should probably take some time to review the
fundamentals of the language.  I would recommend either the official
tutorial or the book "How to Think Like a Computer Scientist":

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 196 bytes
Desc: Digital signature
URL: <>

More information about the Python-list mailing list