In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/02 Report--
This article mainly explains the "Python lambda expression summary", the content of the article is simple and clear, easy to learn and understand, now please follow the editor's train of thought slowly in depth, together to study and learn "Python lambda expression summary" bar!
Lambda expressions are anonymous functions, and they are also seen as anonymous functions without a specific name in other languages. Lambda expressions are very useful because they can make your code more concise. If you don't want to run a function twice in your program, you might want to use lambda expressions, which are exactly the same as ordinary functions. Let's take a look at the prototypes of lambda expressions, code examples, list sorting, list sorting, and lambda expression pros and cons.
1. Prototype:
In the lambda statement, the colon is preceded by a parameter, which can be separated by a comma, and the return value to the right of the colon. What the lambda statement builds is actually a function object. If there are no arguments, then the lambda colon does not precede it.
Lambda parameters: operations (parameters)
2. Code case:
Add = lambda x, y: X + y
Print (add (3,5))
# Output: 8
3. Sort the list
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)]
4. Sort the list and sort
Data = zip (list1, list2)
Data.sort ()
List1, list2 = map (lambda t: list (t), zip (* data))
5. The advantages and disadvantages of lambda expressions.
Functions in Python are more functional and adaptable than lambda expressions, so lambda expressions create simple function objects. On the other hand, the advantages of lambda expressions are also obvious. For example, for single-line code functions, using lambda expressions can save the complex process of defining functions and make the code more concise. For functions that do not need to be used many times, the performance of the program is improved because the lambda expression is released immediately after it is used up.
Thank you for your reading, the above is the content of "Python lambda expression summary", after the study of this article, I believe you have a deeper understanding of the problem of Python lambda expression summary, and the specific use needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.