Posted By

magicrebirth on 12/22/09


Tagged

python lambda


Versions (?)

Who likes this?

1 person have marked this snippet as a favorite

dharmamike


Python: using the Lambda operator


 / Published in: Python
 

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 : 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:

  1. >>>bigger = lambda a, b : a > b
  2. >>>print bigger(1,2)
  3. False
  4. >>>print bigger(2,1)
  5. True

Report this snippet  

You need to login to post a comment.