将阶乘的函数改写成Lambda表达式的形式

 以下是6的阶乘:

from functools import reduce
reduce(lambda x,y:x*y , [1,2,3,4,5,6])

reduce() 函数语法:

reduce(function, iterable[, initializer])

参数

  • function -- 函数,有两个参数
  • iterable -- 可迭代对象
  • initializer -- 可选,初始参数

返回值

返回函数计算结果。

猜你喜欢

转载自blog.csdn.net/weixin_52849741/article/details/127388773
今日推荐