Python math.lgamma() Method

The math.lgamma() method is used to calculate the natural logarithm of the Gamma function value for a given number.

Syntax

import math
math.lgamma(num)

Parameter

num(required): It is a numeric value.

Return Value

It returns the natural logarithm value of the gamma function value of the number in the float datatype.

If num is an either zero(0) or negative integer , it returns a ValueError.

If num is not a number , it returns TypeError.

Visual Representation

Visual Representation of Python math.lgamma() Method

Example 1: How to Use math.lgamma() Method

import math

print(math.lgamma(1))
print(math.lgamma(6))
print(math.lgamma(1.4))
print(math.lgamma(-3.9))

Output

0.0
4.787491742782047
-0.1196129141723708
-0.7094680089083916

That’s it!

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.