Format:
Functools.partail (function, function parameter)-------> int (x, base)-----> functools.partial (int, base)
One, int function
Website Introduction:classint(x, base=10#x为字符串数字, the default string number is a decimal number and the return value is a decimal number
#!/usr/bin/python
# #普通使用
print "int (' 10001 ', 2):", int (' 10001 ', 2) #字符串数字 ' 10001 ' is a 2 binary, the return value is a decimal number
# #自定义使用
def int2 (x, base=2):
return int (x, Base)
Print "Int2 (' 1010101 '):", Int2 (' 1010101 ')
Second, partial function
Website Introduction:
-
functools.partial(func[,*args][, **keywords])?
-
Return a newpartialObject which when called would behave likefuncCalled with the positional argumentsargsand keyword argumentskeywords. Ifmore arguments is supplied to the call, they is appended toargs. ifadditional keyword arguments is supplied, they extend and overridekeywords.
Import Functools #导入模块
Int3 = functools.partial (int, base=2) # Int3: Sets the base parameter of the INT function to the default value 2 binary
Print "Int3 ('):", Int3 (' 100 ')
INT4 = functools.partial (int, ' 2 ') #int4: sets the x parameter of the INT function to the default value ' 2 ', and its base default is decimal
Print "Int4 (' 2 '):", Int4 ()
Python higher order function: Partial (partial function)