用reduce实现阶乘计算

def fact(a,b):
    return a*b

from functools import reduce
print(reduce(fact,range(1,6)))
from functools import reduce

print(reduce(lambda x, y: x * y, range(1, 6)))

 

 

输出:

120

posted on 2017-09-20 17:46  靖康耻  阅读(490)  评论(0编辑  收藏  举报

导航