偏函数可以实现两种功能
1、对参数进行补充,共同处理
# /usr/bin/env Python3
# -*- encoding:UTF-8 -*-
# test.py
from functools import partial
def sum(*args):s = 0for n in args:print(n)return ssum_add_10 = partial(sum,10)
sum_add_10_20 = partial(sum,10,20)
# print("--------原函数sum的函数地址入口")
# print(sum)
# print("--------paritial函数的入口地址")
# print(partial(sum,10))print(sum(1,2,3))
print(sum_add_10(1,2,3))
print(sum_add_10_20(1,2,3))
2、替换下参数的值,便于调试
import functoolsdef mod(m,*,key = 2):return m % key == 0mod_to_2 = functools.partial(mod,key = 3)print(mod(3))
print(mod_to_2(3))