Python Code: Lambda

Lambda is a keyword that indicates the definition of an anonymous function, args is the sequence of arguments (parameters) of the function. result is the result returned by the lambda function.

Just like when creating a regular function, when creating an anonymous function, an object of a functional type is created. However, lambda functions do not receive an identifier for their call. The main purpose of lambda functions is to be used as an argument of another function. A significant advantage of lambda functions over regular functions is that they execute much faster.


# lambda args: result
				
>>> (lambda x, y: x + y)(2, 3)   # simultaneous creation and invocation
5
>>> f = lambda x, y: x + y       # f - reference to the lambda function
>>> f(2, 3)                      # Calling the lambda function through the reference f
5