1. math.factorial(x)

import math
value = math.factorial(x)

2. reduce函数

def factorial(n):
    return reduce(lambda x,y:x*y,[1]+range(1,n+1))

3. 递归实现

def factorial(n):
    if n == 0:
        return 1
    else:
        return n * factorial(n - 1)

相关文章:

  • 2022-01-29
  • 2022-12-23
  • 2022-12-23
  • 2021-09-20
  • 2022-12-23
  • 2021-08-18
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-01-21
  • 2022-12-23
  • 2022-12-23
  • 2021-08-18
  • 2021-08-26
相关资源
相似解决方案