1.1 Anonymous Functions
Sometimes it is easier to pass in anonymous functions without explicitly defining a function.
>>> list (map (Lambda x:x*x, (1, 2, 3, 4, 5))
[1, 4, 9, 16, 25]
before the colon x represents a function parameter .
there is a limit to the anonymous function, that is, there can be only one expression , without writing return, the return value is the result of that expression.
>>> f = Lambda x:x * x
>>> F (2)
4
>>> def build (x, y):
... return x * x + y * y
...
>>> Build (2, 4)
20
>>> def build (x, y):
... return lambda:x * x + y * y
...
>>>
>>> Build (2, 4)
<functionbuild.<locals>.<lambda> at 0x2b8091d87598>
>>> Build (2,4) ()-- call -->lambda again
20
This article is from the "90SirDB" blog, be sure to keep this source http://90sirdb.blog.51cto.com/8713279/1820951
Python Functional Programming--anonymous function lambda