The Lambda keyword in Python can be understood as: It functions like a function pointer.
The official translation of Lambda is an anonymous function, which is relative to the normal function, for example:
Define a normal function that implements the increment 1 operation:
def plus1 (x): return x+1
The above statement implements: 1. Defines a function called: PLUS12. This function has a parameter
The corresponding anonymous function statement writing:
Lambda x:x+1
Note that this is an expression, so he can't actually do anything ...
So if we want to invoke the function to implement the increment 1 operation, we use the normal function and the anonymous function for example, respectively, as follows:
Real-name function implementation:
def plus1 (x): return x+1a = 0a = Plus1 (a) print a
anonymous function implementations:
Func = Lambda x:x+1a = 0a = Func (a) print a
Conclusion
the use of anonymous functions, both as macro definitions in C and as function pointers in the C language。
It's even more fun to combine anonymous and real-name functions, such as:
def plus1 (x): return x+1func = lambda X:plus1 (x) a = 0a = Func (a) print a
you see, this is not the use of function pointers?
The C language has a function pointer that becomes infinitely more flexible, and as well, Python can become equally flexible once lambda is used.
Python Basics-Lambda keyword