Natural Log in Python

Calculate Natural Log of a Number With
log()
Function in Python 
Write EasyToRead Code Using the
import
Statement
This tutorial will introduce methods to calculate the natural log ln
of a number in Python.
Calculate Natural Log of a Number With log()
Function in Python
The log()
function in the NumPy
package returns the natural log of the number passed in the parameters. The natural log of a number has base e
where e = 2.718
. The following code example shows us how to calculate the natural log of a number using the log()
function in Python.
import numpy
x = numpy.log(10)
print(x)
Output:
2.302585092994046
We calculate the natural log of 10 using the numpy.log()
function in the above code. The above code works just fine. But, it is not readerfriendly. In mathematics, log
denotes logarithm with base 10, and ln
denotes natural logarithm with base e
.
Write EasyToRead Code Using the import
Statement
The import
statement is used to import packages and libraries in our code. The following code example shows us how we can make our code more readerfriendly by using the import
statement in Python.
from numpy import log as ln
x = ln(10)
print(x)
Output:
2.302585092994046
In the above code, we changed the log()
function in the NumPy
package to the ln()
function using the import
statement.