recursion with or without return?

Marc 'BlackJack' Rintsch bj_666 at gmx.net
Sun May 25 03:30:44 EDT 2008


On Sun, 25 May 2008 00:00:14 -0700, notnorwegian wrote:

> when using recursion should one use a return statement or not?

This decision has nothing to do with recursion.  It's the same as in
non recursive functions.  If the function calculates something that you
want to return to the caller you have to use ``return``.  If the function
just has side effects, e.g. printing a tree structure recursively, you
don't have to ``return`` something.

> but is there a guideline for this or it just taste or is it
> considering good style or pythonic to always have a returnvalue?

Well, you always have a return value anyway because there's an implicit
``return None`` at the end of every function.

Ciao,
	Marc 'BlackJack' Rintsch



More information about the Python-list mailing list