Assuming that you want to convert a large number of binary strings, each time it is very troublesome to pass in, int(x, base=2) so, we think, can define a int2() function, the default is base=2 passed in:
def int2(x, base=2): return int(x, base)
In this way, it is very convenient for us to convert the binary:
>>> int2(‘1000000‘)64>>> int2(‘1010101‘)85
functools.partialis to help us create a biased function, without our own definition int2() , you can create a new function directly using the following code int2 :
>>> import functools>>> int2 = functools.partial(int, base=2)>>> int2(‘1000000‘)64>>> int2(‘1010101‘)85
So, the simple summary functools.partial of the function is to put some parameters of a function fixed (that is, set the default), return a new function, call this new function is more simple.
When you create a partial function, you can actually receive the function object, *args and **kw these 3 parameters (in fact, the second half of the original text is not read)
Python practical Note (16) functional programming--partial function