What is math.gamma() in Python?

Python is a high-level programming language that provides functionalities for a number of operations.

The math module comes with mathematical methods and constraints that make for straightforward calculations.

math.gamma() returns the gamma function of the number passed as a parameter.

Syntax

math.gamma(x)

Parameters

  • x: A number whose gamma function is to be found. If the number is a negative integer, math.gamma() returns a ValueError. If x is not a number, math.gamma() returns a TypeError. This parameter is required.

Return value

The math.gamma() function returns a floating-point that represents the gamma value at x.

Code example

#import library
import math
#return the gamma values of the numbers
id1 = math.gamma(-0.5)
print("-0.5: ",id1)
id2 = math.gamma(0.0001)
print("0.0001: ",id2)
id3 = math.gamma(26)
print("26: ",id3)
id4 = math.gamma(1.3)
print("1.3: ",id4)
id5 = math.gamma(70)
print("70: ",id5)

Free Resources