The Python GAMMA function is one of the special Python Math function which is used to calculate the Gamma value of the given argument. In this article we will show you, How to use GAMMA() function in Python Programming language with example. Before we step into the syntax, let us see the mathematical formula behind the Gamma function:

**Math.gamma(Number) = (Number – 1)!**

It means, GAMMA() function will subtract one from the Given number and then, finds the factorial. For example, **Math.gamma(6) = 5!**

## Syntax of a Python GAMMA Function

The basic syntax of the GAMMA Function in Python Programming Language is as shown below:

Math.gamma(Number);

**Number:** It can be a number or a valid numerical expression.

- If the
*number*argument is positive integer, GAMMA() function will return the output. - If the
*number*argument is Negative integer, GAMMA() function will return**ValueError.** - If the
*number*argument is positive or negative decimals, GAMMA() function will return the output. - If the
*number*argument is not a number, GAMMA() function will return**TypeError.**

### Python GAMMA Function Example

The Python GAMMA function is used to calculate the Gamma value of the given argument. In this example, We are going to find the same for different data types and display the output

**PYTHON CODE**

# Python GAMMA Function import math Tup = (1, 2, 8, 4 , 5) # Tuple Declaration Lis = [8, 3, 9, 5 , 7] # List Declaration print('Gamma() Function on Positive Number = %d' %math.gamma(2)) print('Gamma() Function on Positive Number = %d' %math.gamma(6)) print('Gamma() Function on Positive Decimal = %.2f' %math.gamma(4.5)) print('Gamma() Function on Negative Decimal = %.2f' %math.gamma(-2.78)) print('Gamma() Function on Tuple Item = %d' %math.gamma(Tup[2])) print('Gamma() Function on List Item = %d' %math.gamma(Lis[2])) print('Gamma() Function on Multiple Number = %d' %math.gamma(10 + 20 - 25)) print('Gamma() Function on String Value = ', math.gamma('3'))

**OUTPUT**

**ANALYSIS**

- At the beginning, We declared Python List and Tuple with some random values.
- Within the first two statements, We passed the Positive integers as the GAMMA() Function argument. From the above screenshot you can observe that, GAMMA() Function is returning output.
- Within the next two statements, We passed both the Positive and negative decimals as the GAMMA() Function argument. As we said before, GAMMA() Function is returning the output.
- Next two statements, We used the Python Tuple and List items as the GAMMA() Function argument. If you observe the above screenshot, GAMMA() function is working perfectly on them.
- Next statement, We assigned multiple values as the argument and the GAMMA() Function worked without any issue.
- Next, We tried GAMMA() Function on String value. As we said before, this will return
as output**TypeError** - Within the Python IDE we passed negative integer as an argument for GAMMA() Function. As you can, it is returning
as output.**ValueError**

Thank You for Visiting Our Blog