lambdas (lambda x: printx)

M

Michal

Hi,

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.

misza
 
E

Erik Max Francis

Michal said:
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 && (e-mail address removed) && 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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Members online

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top