Math Module in Python
Math module
The mathematical operations can be handled by the math module. There are several functions provided by this module like the floor, ceil, log, trunc, etc.
Math Module
We need to import the math module using the import statement.
Math Constants
pi and e are constants defined in the math module.
math.floor()
returns floor value
math.ceil()
returns Ceiling value
math.trunc()
returns equivalent to math.floor for positive numbers and equivalent to math.ceil for negative numbers
Trigonometric functions
math.hypot(num,num))
This method returns equivalent to the square root value.
math.radians(degrees)
This method is used to convert the degrees to radians.
math.sin()
This method returns the sin value.
math.cos()
This method returns the cosine value.
math.tan()
This method returns tangent value.
Inverse sine, cosine and tangent
math.asin()
math.acos()
math.atan()
Hyperbolic sine, cosine, and tangent
math.sinh()
math.cosh()
math.tanh()
Logarithmic calculations
math.log()
When used with two arguments, math.log(x,base)gives the logarithm of x in the given base(i.e. log(x)/ log(base), for example
math.log(1024,2)
math.log(625,5)