[Python-Dev] Let's just *keep* lambda

skip at pobox.com skip at pobox.com
Thu Feb 9 15:52:19 CET 2006

    >> Hmm. Can you give real-world examples (of existing code) where you
    >> needed this?

    Jiwon> Apparently, simplest example is,

    Jiwon> collection.visit(lambda x: print x)

Sure, but has several other people have indicated, statements are not
expressions in Python as they are in C (or in Lisp, which doesn't have
statements).  You can't do this either:

    if print x:
        print 5

because "print x" is a statement, while the if statement only accepts

Lambdas are expressions.  Statements can't be embedded in expressions.  That
statements and expressions are different is a core feature of the language.
That is almost certainly not going to change.


More information about the Python-Dev mailing list