  Python Number Log() Method

Show

Description

The log() method in Python number returns the natural logarithm of x, where x > 0. This log function is another Python Math function that is used for the calculation of the logarithmic value of a certain number comprising of the base e. Python in its math module offers many inbuilt logarithmic functions that allow us to calculate logs making use of a single line.

Syntax

Following is the syntax for log() method:

import math

math.log( x )

Note - This function is not accessible directly, so we need to import the math module, and then we need to call this function using a math static object.

Parameters

• x - This is a numeric expression.

Return Value

This method returns natural logarithm of x, for x > 0.

Example

The following example shows the usage of 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)

When we run the above program, it produces the following result:

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

Here at Intellinuts, we have created a complete Python tutorial for Beginners to get started in Python.