A lambda statement is used to create new function objects and then return them.
Example 15.2. Using Lambda Forms
#!/usr/bin/python # Filename: lambda_form.py def make_repeater(n): return lambda s: s * n twice = make_repeater(2) twicetheword = twice('word') print twicetheword
Here, we use a function make_repeater to create new function objects at runtime and then return it. A lambda statement is used to create the function object which is invoked just like any other function. Essentially, the lambda statement is a function generator. Note that the lambda form's content must be a single expression only - it cannot even be a statement like the print statement.