returning none when it should be returning a list?

Christos Georgiou tzot at sil-tec.gr
Tue May 2 04:48:44 EDT 2006


On 1 May 2006 07:19:48 -0700, rumours say that randomtalk at gmail.com might
have written:

>I'm not sure what "falls off the end" of the function means, i searched
>online, it seems to mean that the function has reached the end
>prematurely and returned a default identifier to signal success or
>not.. Can you please explain what that means?

I think that you haven't grasped the fact that a chain of calls of a
recursive function needs a return for *every* invocation of the function
(but I could be wrong :)

Check the following function, analogous to your own:

>>> def f(x):
    if x > 4:
        print "   returning", x
        return x
    else:
        print "   start recursion"
        f(x+1)
        print "   end recursion"

		
>>> print f(0)
   start recursion
   start recursion
   start recursion
   start recursion
   start recursion
   returning 5
   end recursion
   end recursion
   end recursion
   end recursion
   end recursion
None

Do you see why the function returns None?
-- 
TZOTZIOY, I speak England very best.
"Dear Paul,
please stop spamming us."
The Corinthians



More information about the Python-list mailing list