欢迎光临
我们一直在努力

python怎么拼接两个函数

在python中对两个函数进行拼接,具体方法如下:

1.首先,定义一个装饰工厂;

def decorator_factory(inner_func):

def decorator(outer_func):

def wrapper(*args, **kwargs):

return outer_func(*inner_func(*args, **kwargs))

return wrapper

return decorator

2.装饰工厂定义好后,通过使用装饰工厂进口实现函数拼接;

def f(a, b):

return a, b+2, b+3

@decorator_factory(f)

def g(a, b, c):

return a+b+c

print g(1, 2)

# output: 10

赞(0)
【声明】:本博客不参与任何交易,也非中介,仅记录个人感兴趣的主机测评结果和优惠活动,内容均不作直接、间接、法定、约定的保证。访问本博客请务必遵守有关互联网的相关法律、规定与规则。一旦您访问本博客,即表示您已经知晓并接受了此声明通告。