def sub(x, y):
return x - y
def div(x, y):
return x/y
def attach_wrap(func1, func2=None):
if func2 is None:
return partial(attach_wrap, func1)
setattr(func1, func2.__name__, func2)
return func1
sub1 = attach_wrap(sub)
print(sub1)
sub2 = sub1(div)
print(sub2)
print(sub2(20, 10)) //10
print(sub2.div(20, 10)) //2.0
functools.partial 偏函数
python相关文章
最近热门
最常浏览
- 016 推荐系统 | 排序学习(LTR - Learning To Rank)
- 偏微分符号
- i.i.d(又称IID)
- 利普希茨连续条件(Lipschitz continuity)
- (error) MOVED 原因和解决方案
- TextCNN详解
- 找不到com.google.protobuf.GeneratedMessageV3的类文件
- Deployment failed: repository element was not specified in the POM inside distributionManagement
- cannot access com.google.protobuf.GeneratedMessageV3 解决方案
- CLUSTERDOWN Hash slot not served 问题原因和解决办法
×