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