Functions

Lambda in Python

A lambda is a function that is declared and executed at the same time. It is an anonymous function.


Syntax
#declare and run code, all at once
(lambda input_param: code to run)(passed_params)

#lambdas can be assigned to variables
lambda_variable = (lambda inpu_param: code to run)

#running an assigned lambda
lambda_variable(passed_params)

Notes

Lambdas were made to take advantage of the ability to pass functions as parameters to first class functions.


Example
add_three = (lambda x: x + 3)
print (add_three(1)) #should print 4

< First Class Functions   |   Map >

© 2018 SyntaxDB. All Rights Reserved.