Python Learning (v) Function--built-in function lambda filter map reduce

Source: Internet
Author: User

Python built-in functions lambda, filter, map, reduce

Python has built in some of the more special and useful functions that make your code simple and easy to read.

The following is a preliminary study of Python's lambda, filter, map, and reduce.

Lambda Anonymous functions

In a lambda statement, the colon is preceded by a parameter, which can have multiple, separated by commas, and a return value to the right of the colon.

The lambda statement is actually built as a function object, as in the following example to feel the Lambda anonymous function:

1 def F (i):             #  user-definable return square number 2     return i*i3  Print(f (3))45Lambda x:x*x    #  Lambda anonymous function  6print(g (3))

The lambda function, compared to the normal function, omits the function name, while such anonymous functions cannot be shared elsewhere, and there are many other ways to replace Lambda.

Is it not necessary to have a lambda? In the present sense, Lambda has the following advantages:

1. Eliminate the process of defining simple functions, quickly define the minimum function of a single line, and make the code more streamlined

2. Functions that do not need to be reused, without defining function names

3. Use with filter map reduce

A lambda is similar to a macro in C, borrowed from Lisp, and c#3.0 begins with a similar expression, the keyword is =>, and is referenced as follows:

1 var New int [] {23579}; 2 var 3);      // [5, 6, 9]

    

Python Learning (v) Function--built-in function lambda filter map reduce

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.