pytest插件的理解

先介绍几个概念:

回调函数:通俗讲是说把一个函数作为参数传给另一个函数,第一个函数称为回调函数

def computer(a, b, func):
    return func(a, b)


def max(a, b):
    return [a, b][a < b]  # 意思是如果a<b,则返回a,否则返回b


def min(a, b):
    return [a, b][a > b]


def sum(a, b):
    return str(int(a) + int(b))


if __name__ == "__main__":
    a = input("请输入整数a:")
    b = input("请输入整数b:")
    res = computer(a, b, max)
    print("Max of " + a + " and " + b + " is " + res)
    res = computer(a, b, min)
    print("Min of " + a + " and " + b + " is " + res)
    res = computer(a, b, sum)
    print("Sum of " + a + " and " + b + " is " + res)


输出结果:
请输入整数a:5
请输入整数b:6
Max of 5 and 6 is 6
Min of 5 and 6 is 5
Sum of 5 and 6 is 11
回调函数举例

 

posted @ 2020-03-30 19:24  爱打盹的猫猫  阅读(260)  评论(0编辑  收藏  举报