Partial function
首先简单说functools.partialis to fix some parameters of a function (that is, to set a default value), to return a new function, and to call the new function is simpler.
My understanding is that, like C + +, a function with a parameter two times encapsulated, let him meet my actual needs, call more concise
Example:
#assuming that the int (x, base = 10) is two times encapsulated#Usual proceduredefTo_int2 (x):returnint (x, base = 2)Print(To_int2 ('101'))#Partial function approachImportfunctoolsto_int2_partial= functools.partial (int, base = 2)Print(To_int2_partial ('101', base=2))#function declaration of partial#def __init__ (self, func, *args, **keywords):#This is where you can see that it's actually done.#Int (**keywords) ==>kw = {' Base ' = 2} However ' 101 ' is passed into the function in the form of *argsPrint(To_int2_partial ('101', base=10))#result --101
Python Learning Note: partial functions