lambdas (lambda x: printx)

Erik Max Francis max at alcyone.com
Wed Dec 3 15:54:45 EST 2003


Michal wrote:

> Today I started with python and I cannot understand why expresion
> lambda x: print x
> returns syntax error (but for example lambda x: sys.stdio.write(x)
> does not)
> First I fought the reason is scopeing, but it shouldnt return syntax
> error.

The problem is that you can only put an expression in a lambda form. 
print is a statement, not an expression.  Other examples of statements
are if...else control structures, variable assignments, and return
statements.

-- 
   Erik Max Francis && max at alcyone.com && http://www.alcyone.com/max/
 __ San Jose, CA, USA && 37 20 N 121 53 W && &tSftDotIotE
/  \ 
\__/ Bring me men / Bring me men to match my plains
    -- Lamya




More information about the Python-list mailing list