new_func = partial(函数名,参数), 生成一个新的函数, 新的函数中参数是partial固定时的参数
例1:
from functools import partial def func(a, b): return a+b new_func = partial(func, 3) ret = new_func(3) print(ret) # 6 # basetwo = partial(int, base=2) # basetwo('0') print(int('12', 16)) # 18
例2:
from functools import partial def func(*a,**b): print(a) print(b) return a new_func = partial(func,3) print(new_func,func) ret = new_func() # functools.partial(<function func at 0x000001930F1B2E18>, 3) <function func at 0x000001930F1B2E18> # (3,) # {}