Home > Article > Backend Development > Comprehensive analysis of Lambda expressions in Python
What is a Lambda expression
"Lambda expression" (lambda expression) is an anonymous function. Lambda expression is named based on the lambda calculus in mathematics. It directly corresponds to the lambda abstraction (lambda abstraction). It is an anonymous function, that is, a function without a function name. . Lambda expressions can represent closures (note that they are different from the traditional mathematical sense).
Lambda is an anonymous function. When we need to call a certain function repeatedly and don’t want to write so much code, we can use lambda expressions instead.
Universal format of lambda:
lambda argument: manipulate(argument)
Sample code:
add = lambda x,y : x + y
print add(3,5)
#output: 8
Usage:
Sort.
a = [(1, 2), (4, 1), (9, 10), (13, -3)] a.sort(key=lambda x: x[1]) print(a) # Output: [(13, -3), (4, 1), (1, 2), (9, 10)]
The above is the Lambda expression in Python introduced by the editor. I hope it will be helpful to you. If you have any questions, please leave me a message and the editor will reply to you in time. I would also like to thank you all for your support of the Script House website!