Question on lambdas

Chris Angelico rosuav at gmail.com
Mon Dec 8 20:53:05 EST 2014


On Tue, Dec 9, 2014 at 12:44 PM, Christoph Becker <cmbecker69 at gmx.de> wrote:
> Ben Finney wrote:
>
>> It's best to remember that ‘lambda’ is syntactic sugar for creating a
>> function; the things it creates are not special in any way, they are
>> normal functions, not “lambdas”.
>
> Could you please elaborate why ‘lambda’ does not create “lambdas”.  I'm
> a Python beginner (not new to programming, though), and rather confused
> about your statement.

For the same reason that "def" doesn't create "defs", and "for"
doesn't create fors (uhh... the Force?). Both "lambda" and "def"
create functions. Functions are things that can be called, and they're
created by the "def" statement, the "lambda" expression, and very VERY
occasionally, by directly calling the function constructor. You could
distinguish between "lambda functions" and "def functions" if you
like, but the distinction is almost never significant. In fact,
usually you don't even need to distinguish between functions and other
callables (types, objects with __call__ methods, bound method objects,
etc, etc, etc).

ChrisA



More information about the Python-list mailing list