用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
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