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

**Math.lgamma(Number) = math.log( (Number – 1)! )**

It means,

- First, LGAMMA() function will implement the Gamma function on the given number. Please refer Python Gamma function article for further reference.
- Next, LGAMMA() function will calculate the Natural logarithm of the Gamma function output. Please refer Python Log function article to understand the math.log() function.

For example, *Math.gamma(6) = 5! = 120*

*Math.lgamma(6) = math.log(120) = 4.79*

## Syntax of a Python LGAMMA Function

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

Math.lgamma(Number);

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

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

### Python LGAMMA Function Example

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

**PYTHON CODE**

# Python LGAMMA Function import math Tup = (1, 2, 8, 4 , 5) # Tuple Declaration Lis = [8, 3, 9, 5 , 7] # List Declaration print('LGamma() Function on Positive Number = %.2f' %math.lgamma(2)) print('LGamma() Function on Positive Number = %.2f' %math.lgamma(6)) print('LGamma() Function on Positive Decimal = %.2f' %math.lgamma(4.5)) print('LGamma() Function on Negative Decimal = %.2f' %math.lgamma(-2.78)) print('LGamma() Function on Tuple Item = %.2f' %math.lgamma(Tup[2])) print('LGamma() Function on List Item = %.2f' %math.lgamma(Lis[2])) print('LGamma() Function on Multiple Number = %.2f' %math.lgamma(10 + 20 - 25)) print('LGamma() Function on String Value = ', math.lgamma('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 LGAMMA() Function argument. From the above screenshot you can observe that, LGAMMA() Function is returning output.
- Within the next two statements, We passed both the Positive and negative decimals as the LGAMMA() Function argument. As we said before, LGAMMA() Function is returning the output.
- Next two statements, We used the Python Tuple and List items as the LGAMMA() Function argument. If you observe the above screenshot, LGAMMA() function is working perfectly on them.
- Next statement, We assigned multiple values as the argument and the LGAMMA() Function worked without any issue.
- Next, We tried LGAMMA() 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 LGAMMA() Function. As you can, it is returning
as output.**ValueError**

Thank You for Visiting Our Blog