lambdas (lambda x: printx)

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Michal

    lambdas (lambda x: printx)

    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


  • Erik Max Francis

    #2
    Re: lambdas (lambda x: printx)

    Michal wrote:
    [color=blue]
    > 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.[/color]

    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@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

    Comment

    Working...