Python math module is defined as the most popular mathematical functions, which includes trigonometric functions, representation functions, logarithmic functions, etc. Furthermore, it also defines two mathematical constants, i.e., Pie and Euler number, etc.
Pie (n): It is a well-known mathematical constant and defined as the ratio of circumstance to the diameter of a circle. Its value is 3.141592653589793.
Euler's number(e): It is defined as the base of the natural logarithmic, and its value is 2.718281828459045.
There are different math modules which are given below:
This method returns the natural logarithm of a given number. It is calculated to the base e.
import math number = 2e-7 # small value of of x print('log(fabs(x), base) is :', math.log(math.fabs(number), 10))
This method returns base 10 logarithm of the given number and called the standard logarithm.
import math x=13 # small value of of x print('log10(x) is :', math.log10(x))
This method returns a floating-point number after raising e to the given number.
import math number = 5e-2 # small value of of x print('The given number (x) is :', number) print('e^x (using exp() function) is :', math.exp(number)-1)
This function returns the square root of any given number.
import math x = 20 y = 14 z = 17.8995 print('sqrt of 20 is ', math.sqrt(x)) print('sqrt of 14 is ', math.sqrt(y)) print('sqrt of 17.8995 is ', math.sqrt(z))
This method returns e raised to the power of any number minus 1. e is the base of natural logarithm.
import math number = 2e-1 # small value of of x print('The given number (x) is :', number) print('e^x (using expml() function) is :', math.expm1(number))
It returns the cosine of any number, in radians.
import math angleInDegree = 60 angleInRadian = math.radians(angleInDegree) print('Given angle :', angleInRadian) print('cos(x) is :', math.cos(angleInRadian))
It returns the sine of any number, in radians.
import math angleInDegree = 60 angleInRadian = math.radians(angleInDegree) print('Given angle :', angleInRadian) print('sin(x) is :', math.sin(angleInRadian))
It returns the tangent of any number, in radians.
import math angleInDegree = 60 angleInRadian = math.radians(angleInDegree) print('Given angle :', angleInRadian) print('tan(x) is :', math.tan(angleInRadian))