代码点读机 / Python / math.factorial

math.factorial Python · 模块功能

计算阶乘,从 1 乘到它本身。

怎么用

import math
math.factorial(n)

小例子

import math
print(math.factorial(5))

运行结果

120

提醒:n 必须是非负整数。

官方文档:https://docs.python.org/zh-cn/3/library/math.html#math.factorial

在代码里遇到不认识的词?打开代码点读机,点一下就懂 → ← Python全部词条