Python math.gamma() 方法
定义和用法
math.gamma()
方法返回数的 gamma 值。
gamma 值等于 factorial(x-1)
。
提示:如需求数的对数 gamma 值,请使用 math.lgamma() 方法。
实例
求不同数字的 gamma 值:
# 导入 math 库 import math # 返回不同数字的 gamma 值 print (math.gamma(7)) print (math.gamma(-4.2))
语法
math.gamma(x)
参数
参数 | 描述 |
---|---|
x |
必需。要计算其 gamma 值的数字。 如果数字是负整数,它将返回 ValueError。 如果它不是数字,它将返回 TypeError。 |
技术细节
返回值: | 浮点数值,表示数的 gamma 值。 |
---|---|
Python 版本: | 2.7 |