Q about tail recursion

Michael Hudson mwh21 at cam.ac.uk
Sun Feb 27 10:33:38 EST 2000

Robin Becker <robin at jessikat.demon.co.uk> writes:

> I quite often want to use None as an exceptional return eg in the case
> of a list returning function [] might be a legal return and None an
> illegal one. That way I can leave the error handling to the caller. I
> guess I should really be raising an exception though to be truly
> pythonian.


def f(x):
    if x:
        return 1
        return None

compiles differently to

def f(x):
    if x:
        return 1

and the code I've just posted clears the former but moans about the
latter, which I belive was the idea all along (hope so anyway...).


very few people approach me in real life and insist on proving they are
drooling idiots.                         -- Erik Naggum, comp.lang.lisp

More information about the Python-list mailing list