python偏函数
时间:2017-08-08 21:28:22
收藏:0
阅读:250
python中functools.partial模块,可以用来定义偏函数,如:
def func(x, y): return x+y result = func(2,10) print(result)
运行结果:
12
可以将带默认值的函数,使用functools.partial进行封装,封装后的函数叫做偏函数
def func(x, y, z): return x-y-z func2 = functools.partial(func, 5) result = func2(2,1) print(result)
运行结果:
2
函数的默认参数,放在所有参数的左边。
原文:http://www.cnblogs.com/shijingjing07/p/7308805.html
评论(0)