Python math.gamma() Method

Python math 模块Python math Module

Python math.gamma(x)The method returns the gamma function (Gamma function) at x.

The gamma function, also known as the second Euler integral, is a class of functions that extends the factorial function to real and complex numbers.

To find the log-gamma value of a number, usemath.lgamma()method.

Python version: 3.2

Syntax

The syntax of the math.gamma() method is as follows:

math.gamma(x)

Parameter description:

  • x-- Required, a number. If the number is a negative integer, it returns ValueError. If it is not a number, it returns TypeError.

Return Value

A floating-point value representing the gamma function at x.

Example

The following example calculates the gamma function of different numbers:

Example

# Import the math package
import math

# Calculate the gamma function of different numbers
print(math.gamma(-0.1))
print(math.gamma(8))
print(math.gamma(1.2))
print(math.gamma(80))
print(math.gamma(-0.55))

Output result:

-10.686287021193193
5040.0
0.9181687423997604
8.946182130782976e+116
-3.578429819277059

Python math 模块Python math Module

Other extensions