Python的math
库确实提供阶乘函数,具体信息如下:
-
阶乘函数存在性
math
库中包含math.factorial()
函数,用于计算非负整数的阶乘。例如,math.factorial(5)
返回120。 -
函数使用方法
需先导入
math
模块,然后直接调用math.factorial(n)
,其中n
为要计算阶乘的非负整数。 -
其他相关说明
-
部分资料提到
math
库没有阶乘函数,可能因版本差异或信息混淆,但高权威性来源已明确确认存在math.factorial()
。 -
若需计算复数阶乘,需使用
cmath
模块。
-
示例代码 :
import math
print(math.factorial(5)) # 输出: 120