Why use lambda expressions
This article is about why you use lambda expressions. The editor thinks it is very practical, so share it with you as a reference and follow the editor to have a look.
Preface
The syntax structure of the lambda expression:
#! / usr/bin/python3 # writable function description sum = lambda arg1, arg2: arg1 + arg2 # calls sum function print ("added value is:", sum (10,20)) print ("added value is:", sum (20,20))
Knowing lambda expression for the first time
In fact, lambda acts like a function. Here are the parameters and return values of the python function and lambda expression.
In fact, from this point of view, the lambda syntax is very concise, generally only one line can achieve certain functions.
Why use lambda expressions
Since both lambda expressions and python functions can achieve the same effect, why use lambda expressions?
a. Sometimes where the python function cannot be used, the lambda expression can still be used, and it is more convenient and concise.
b. Functions have to be named, but this is a difficult thing to do and easy to repeat, but lambda expressions are not quite a problem.
C. the lambda expression requires only one line, which enhances the readability of the code
Thank you for reading! This is the end of the article on "Why use lambda expressions". I hope the above content can be of some help to you, so that you can learn more knowledge. if you think the article is good, you can share it for more people to see!