Return to Snippet

Revision: 21862
at December 22, 2009 15:26 by magicrebirth


Initial Code
>>>bigger = lambda a, b : a > b
>>>print bigger(1,2)
False
>>>print bigger(2,1)
True

Initial URL


Initial Description
The lambda operator built in to the Python language provides a method to create anonymous functions. This makes it easier to pass simple functions as parameters or assign them to variable names. The lambda operator uses the following syntax to define the function:
lambda <args> : <expression>
The term args refers to a list of arguments that get passed to the function. The term expression can be any legal Python expression. The following code shows an example of using the lambda operator to assign an anonymous function to a variable:

Initial Title
Python: using the Lambda operator

Initial Tags
python

Initial Language
Python