anonymous functions
When we pass in a function, there are times when we do not need to explicitly define the function and pass in the anonymous function directly. As below
lambda x: x*x
In Python, the keyword lambda represents an anonymous function, and the x preceding the colon represents the function parameter
The anonymous function has a restriction that there can be only one expression, without writing return, the return value is the result of that expression.
Benefits: Prevent function name collisions, in addition to anonymous functions is a function object, you can also assign an anonymous function to a variable, and then use the variable to invoke the function.
Adorner (decorator)
Decorator can enhance the function of functions, although it is a bit complicated to define, but it is very convenient to use.
The specific reference Liaoche is the official tutorial. Https://www.liaoxuefeng.com/wiki/0014316089557264a6b348958f449949df42a6d3a2e542c000/ 0014318435599930270c0381a3b44db991cd6d858064ac0000
Partial function
def int2(x,base=2): return int(x,base)
Python's Functools module provides a number of useful functions, one of which is the partial function.
Functools.partial is to help us create a biased function that does not require us to define INT2 ().
import functoolsint2 = functools.partial(int,base = 2)int2(‘1000000‘)//64
Anonymous functions, adorners, and partial functions of python functional programming