Latest web development tutorials

Python log () function

Python figures Python figures


description

log () method returns the natural logarithm of x.


grammar

The following is the syntax log () method:

import math

math.log( x )

Note: log () is not directly accessible, we need to import math module, invoke the method through static object.


parameter

  • x - numeric expression.

return value

Returns the natural logarithm of x, x> 0.

Examples

The following shows an example of using the log () method:

#!/usr/bin/python
import math   # This will import math module

print "math.log(100.12) : ", math.log(100.12)
print "math.log(100.72) : ", math.log(100.72)
print "math.log(119L) : ", math.log(119L)
print "math.log(math.pi) : ", math.log(math.pi)

After running the above example output is:

math.log(100.12) :  4.60636946656
math.log(100.72) :  4.61234438974
math.log(119L) :  4.77912349311
math.log(math.pi) :  1.14472988585

Python figures Python figures