# Gamma Function In Python

Hello friends, In this segment, we are going to discuss the GAMMA function. So let us start, a gamma function is a mathematical function which returns a gamma value.

Now we will know how a gamma value is calculated. When we calculate a gamma value of any number it simply returns (n-1)! of the given number.

Γn=(n-1)!

The above expression is written in mathematics for calculating gamma function. Here n is the number which gamma value we have to calculate.

## Python Gamma Function

In Python programming language we have a gamma function where we have to pass only that value which gamma value we want. The syntax for writing the gamma function is given below.

math.gamma(x)

In the above statement, we passed an argument x. Here x is that number which gamma value we want to calculate. For using the gamma function in Python first we have to import the math module which already exists. For importing the math module we write import math on our IDE. This module gives access to us to use the library function.

Key points

• Gamma function returns the value for a positive integer.
• It also returns the value for positive decimal.
• Even it returns the value for negative decimal.
• But when you pass a negative integer in arguments it returns Value Error.
```import math
print(math.gamma(2.3))```

Output:

```1.16671190519816

```

Now let me show you if you pass a negative integer as an argument in gamma function what result you will get.

```import math
print(math.gamma(-2))```

Output:

`ValueError: math domain error.`

As I already told you that whenever you will pass a negative integer it will throw Value Error as a result.