当前位置:首页 > python教程 > python进阶

Python math.gamma() 方法

python math.gamma() 方法

python math 模块

python math.gamma(x) 方法返回 x 处的伽玛函数(gamma 函数)。

伽玛函数,也叫欧拉第二积分,是阶乘函数在实数与复数上扩展的一类函数。

要查找数字的对数伽玛值,请使用 math.lgamma() 方法。

python 版本: 3.2

语法

math.gamma() 方法语法如下:

math.gamma(x)

参数说明:

  • x -- 必需,数字。如果数字是负整数,则返回 valueerror。 如果不是数字,则返回 typeerror。
返回值

一个浮点值,表示表示 x 处的伽玛函数。

实例

以下实例计算不同数的伽玛函数:

实例

# 导入 math 包
import math

# 计算不同数的伽玛函数
print(math.gamma(-0.1))
print(math.gamma(8))
print(math.gamma(1.2))
print(math.gamma(80))
print(math.gamma(-0.55))

输出结果:

-10.686287021193193
5040.0
0.9181687423997604
8.946182130782976e+116
-3.578429819277059


【说明】本文章由站长整理发布,文章内容不代表本站观点,如文中有侵权行为,请与本站客服联系(QQ:254677821)!