lambda 4 dummies

Rene Pijlman reply.in at the.newsgroup
Tue Mar 4 07:26:59 EST 2003


Giuseppe Ricioppo:
>Given the following code:
>
>        >>> f = lambda a, b, c: a + b +c
>        >>> f(1,1,1)
>        3
>
>Here, f is assigned the function object the lambda expression returns. 
>Is f, the object returned, a reference to an anonymous function?

Yes.

>>> f = lambda a, b, c: a + b +c
>>> f
<function <lambda> at 0x00749260>
>>> type(f)
<type 'function'>

Section 5.11 of the Python Language Reference 2.2:
"Lambda forms (lambda expressions) have the same syntactic
position as expressions. They are a shorthand to create
anonymous functions; the expression lambda arguments: expression
yields a function object. The unnamed object behaves like a
function object defined with

def name(arguments):
    return expression"

-- 
René Pijlman




More information about the Python-list mailing list