Python Data Persistence – Math Module
As you would expect, the math built-in module is one of the most frequently used. Various functions which are often required are defined in this module. Functions for computing all trigonometric ratios are present in the math module. All these functions calculate the respective ratio of an angle given in radians. Knowing that 30 degrees are roughly equal to 0.5236, various ratios are calculated as follows:
|>>> import math
- Degrees() and Radians() in Python
- Python Program to Get Tangent value Using math.tan()
- Python Program to Find the Sine Series for the Given range
The math module also has two functions to convert the measure of an angle in degrees to radians and vice versa.
Two important mathematical constants are defined in this module. They are Pie (π) and Euler’s number (e)
We have used sqrt ( ) function from math module. Likewise the module has pow ( ) , log ( ) , and exp ( ) functions.
|>>> math . sqrt ( 25 )
>>> math . pow ( 5 , 2 )
>>> math.log(10) #natural logarithm using math.e as base
>>> math.loglO(100) ttstandard logarithm using 10 as base
The mod operator (%) and floor operator (//) were introduced earlier. This module contains similar functions ( remainder ( ) and floor ( ) ). Another ceil( ) function in this module returns the nearest integer of a division operation.
|>>> math.remainder(10,6) #Difference between numerator and closest integer multiple of denominator
>>> math.floor(10/6) #Returns the largest integer < = given float
>>> math.ceil(10/6) #Returns the smallest integer >= float