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
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!
Ankit Lathiya is a Master of Computer Application by education and Android and Laravel Developer by profession and one of the authors of this blog. He is also expert in JavaScript and Python development.