# This is a learning note for the Liaoche teacher Python tutorial
1. Overview
Partial function is a function of the Functools module
The role of Functools.partial is based on an existing function. It is easier to call this new function by pinning some of its parameters (that is, setting the default value) and then returning a new function .
1.1, Functools. Partial application
Known:
The INT function can be ' 123 '--123.
The base parameter of int can be converted in N-binary
>>>int(' 12345 ', base=8)
5349
>>>int(' 12345 ', -)
74565
Use:
# Partial defines a function that has a fixed 2-binary conversion
Int2 = functools.partial (int, base=2) # After the definition, we can still replace the base value with other values, just like the default parameters
Analytical:
When you create a partial function, you can actually receive the 3 parameters of the function object, *args, and **kw.
When incoming:
Int2 = functools.partial (int, base=2)
Equivalent:
KW = {' base ': 2} # Fixed a keyword argument
Int (' 10010 ', **kw)
When incoming:
Max2 = functools.partial (max) # 10 is automatically added to the right as part of the *args
Equivalent:
args = (10, 5, 6, 7)
Max (*args)
Add:
For cases like the POW () parameter, the range () parameter, has multiple parameters.
P=functools.partial (pow,2), the first parameter is fixed
Python Learning note __4.5 partial function (binding function parameter)