Python函数名为参数

1.定义两个函数,求和函数和最大函数

def add(x, y):
    return x + y

def maxnum(x, y):
    return  x if x > y else y

 

lst= [2, 4, 6, 9,8,98,34,90]
def reduce_(function, liste , initial):
    result = initial
    for num in liste:
        result = function(result, num)
    return result

print(reduce_(maxnum, lst, 0))
print(reduce_(add, lst, 0))

 

posted @ 2016-08-08 19:52  hjhsysu  阅读(687)  评论(0编辑  收藏  举报