函数在执行时,要带上所有必要的参数进行调用。但是,有时参数可以在函数被调用之前提前获知。这种情况下,
一个函数有一个或多个参数预先就能用上,以便函数能用更少的参数进行调用。通过设定参数的默认值,可以降低函
数调用的难度。这里的话就要用到偏函数了。
例如:
import functools
def add(a,b):
return a+b
add(2,3)
#输出结果为:5
plus = functools.partial(add,10)
#这里的话,将10设置成了参数的默认值
plus(1)
#输出的结果为11
plus(add(3,4))
#输出的结果为17