[Python]reduce function & lambda function & factorial
Posted profesor
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了[Python]reduce function & lambda function & factorial相关的知识,希望对你有一定的参考价值。
from functools import reduce i = int(input("input a number 1-10: ")) result = reduce(lambda a, b: a*b, [item for item in range(1,i+1)]) print(f‘factorial of {i+1} is {result}‘)
运行结果
input a number 1-10: 5 factorial of 6 is 120
以上是关于[Python]reduce function & lambda function & factorial的主要内容,如果未能解决你的问题,请参考以下文章
[译]PYTHON FUNCTIONS - MAP, FILTER, AND REDUCE