The lambda operator

In Python, functions are first-class objects

  • This means you can manipulate functions like all other types (integers, floats, lists, etc...)
     def add(a,b):
         return a+b
     
     a = add      
     print a(3,4) 

You can also create anonymous functions with lambda

     a = lambda x,y: x+y
     ...
     b = a(3,4)
  • This is particularly useful for callback functions
  • However, lambda can only be used to specify simple expressions.
<<< O'Reilly OSCON 2000, Introduction to Python, Slide 85
July 17, 2000, beazley@cs.uchicago.edu
>>>