In this tutorial, you will learn python math module with example and import math python module. Python math module is basically a standard module available it also provides mathematical functions to the developers. Some of the mathematical functions are written in the math module as algorithmic functions, angle conversion functions. To use the function in math module start by including module using import statement. To import the math module we write as follows,
python math module example :-
e-This represents mathematical constant e.
pi- This represents mathematical constant pi.
Python Math modules:-
Math.log ():-The method will return the natural logarithm of given number and calculated to the base ‘e’.
e.g:-
Import math
Number = 2e-7
Print ('log(fabs(x), base) is :
math.log (math.fabs(number), 10))
O/p:-
log (fabs(x), base) is : -6.698970004336019
This method returns base 10 logarithm of the number and is called as standard logarithm.
Example:-
Import math
x=13 # small value of of x
Print ('log10(x) is:’ math.log10(x))
O/p:-
log10(x) is: 1.1139433523068367
This method returns a floating-point number after raising e to the given number.
Example:-
Import math
Number = 5e-2
Print ('The given number (x) is :', number)
Print ('e^x (using exp() function) is :', math.exp(number)-1)
O/p:-
The given number (x) is: 0.05
e^x (using exp() function) is : 0.05127109637602412
This function returns the square root of any given number.
Example:-
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))
O/p:-
sqrt of 20 is 4.47213595499958
sqrt of 14 is 3.7416573867739413