Partial Function- when a function has too many arguments to simplify, use the functools.partial
You can create a new function that can fix some of the parameters of the original function, making it easier to invoke.
Import Functools
Int2 = functools.partial (int,base=2)
print int (' 1000000 ', 2)
# 64
Print Int2 (' 1000000 ')
# 64
A simple summary of the role of functools.partial is to fix certain parameters of a function (that is, set default values), return a new function, and make it easier to call the new function.
Notice that the new Int2 function above simply re-sets the base parameter to the default value of 2, but can also pass in other values when the function is called:
Int2 (' 1000000 ', base=10)
1000000
To create a partial function, the right-to-left fixed parameter, that is, for the function f (A1, A2, A3), can be fixed A3, can also be fixed A3 and A2, but also fixed a3,a2 and A1, but do not jump fixed, such as only fixed A1 and A3, the A2 leaked. If you do this, calling the new function is more complicated and you can try it yourself.
10 minutes a day, 12 days Getting Started Python (vi)