Python/ref math factorial
来自菜鸟教程
<languages />
Python math.factorial()方法
例
查找数字的阶乘:
#Import math Library
import math
#Return factorial of a number
print(math.factorial(9))
print(math.factorial(6))
print(math.factorial(12))
定义和用法
The
math.factorial()
方法返回数字的阶乘。
注意: 此方法仅接受正整数。
一个数字的阶乘是从我们指定的数字到1的所有整数的乘积之和。例如,阶乘6为6 x 5 x 4 x 3 x 2 x 1 = 720
句法
math.factorial(x)
参数值
| 参数 | 描述 |
|---|---|
| x | 需要。一个正整数。如果数字为负数或非整数,则返回ValueError。如果该值不是数字,则返回TypeError |
技术细节
| 返回值: | 积极的
|
| Python版本: | 2.6 |