[Tutor] Lambda?? Whaaaaat?
Dwight Hutto
dwightdhutto at gmail.com
Fri Aug 31 06:20:56 CEST 2012
Hey Scott,
Always refer to google and the python docs first.
from http://docs.python.org/tutorial/controlflow.html#lambda-forms
4.7.5. Lambda Forms
By popular demand, a few features commonly found in functional programming
languages like Lisp have been added to Python. With the
lambda<http://docs.python.org/reference/expressions.html#lambda>keyword,
small anonymous functions can be created. Here’s a function that
returns the sum of its two arguments: lambda a, b: a+b. Lambda forms can be
used wherever function objects are required. They are syntactically
restricted to a single expression. Semantically, they are just syntactic
sugar for a normal function definition. Like nested function definitions,
lambda forms can reference variables from the containing scope:
>>>
>>> def make_incrementor(n):... return lambda x: x + n...>>> f = make_incrementor(42)>>> f(0)42>>> f(1)43
and also, this looks interesting as well:
http://www.diveintopython.net/power_of_introspection/lambda_functions.html
I haven't used lambdas but a few times, so a little google research can go
a long way.
Sincerely,
David Hutto
http://hitwebdevelopment.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20120831/2dd31246/attachment.html>
More information about the Tutor
mailing list