Python Mathematical Functions

The math module is used to access mathematical functions in the Python. All methods of this functions are used for integer or real type objects, not for complex numbers.
To use this module, we should import that module into our code.
import math

These constants are used to put them into our calculations.
pi
Return the value of pi: 3.141592
E
Return the value of natural base e. e is 0.718282
tau
Returns the value of tau. tau = 6.283185
inf
Returns the infinite
nan
Not a number type.
These functions are used to represent numbers in different forms. The methods are like below −
ceil(x)
Return the Ceiling value. It is the smallest integer, greater or equal to the number x.
copysign(x, y)
It returns the number x and copy the sign of y to x.
fabs(x)
Returns the absolute value of x.
factorial(x)
Returns factorial of x. where x ≥ 0
floor(x)
Return the Floor value. It is the largest integer, less or equal to the number x.
fsum(iterable)
Find sum of the elements in an iterable object
gcd(x, y)
Returns the Greatest Common Divisor of x and y
isfinite(x)
Checks whether x is neither an infinity nor nan.
isinf(x)
Checks whether x is infinity
isnan(x)
Checks whether x is not a number.
remainder(x, y)
Find remainder after dividing x by y.
import math
print('The Floor and Ceiling value of 23.56 are: ' + str(math.ceil(23.56)) + ', ' + str(math.floor(23.56)))
x = 10
y = -15
print('The value of x after copying the sign from y is: ' + str(math.copysign(x, y)))
print('Absolute value of -96 and 56 are: ' + str(math.fabs(-96)) + ', ' + str(math.fabs(56)))
my_list = [12, 4.25, 89, 3.02, -65.23, -7.2, 6.3]
print('Sum of the elements of the list: ' + str(math.fsum(my_list)))
print('The GCD of 24 and 56 : ' + str(math.gcd(24, 56)))
x = float('nan')
if math.isnan(x):
    print('It is not a number')
x = float('inf')
y = 45
if math.isinf(x):
    print('It is Infinity')
print(math.isfinite(x)) #x is not a finite number
print(math.isfinite(y)) #y is a finite number
The Floor and Ceiling value of 23.56 are: 24, 23
The value of x after copying the sign from y is: -10.0
Absolute value of -96 and 56 are: 96.0, 56.0
Sum of the elements of the list: 42.13999999999999
The GCD of 24 and 56 : 8
It is not a number
It is Infinity
False
True

These functions are used to calculate different power related and logarithmic related tasks.
pow(x, y)
Return the x to the power y value.
sqrt(x)
Finds the square root of x
exp(x)
Finds xe, where e = 2.718281
log(x[, base])
Returns the Log of x, where base is given. The default base is e
log2(x)
Returns the Log of x, where base is 2
log10(x)
Returns the Log of x, where base is 10
 Live Demo
import math
print('The value of 5^8: ' + str(math.pow(5, 8)))
print('Square root of 400: ' + str(math.sqrt(400)))
print('The value of 5^e: ' + str(math.exp(5)))
print('The value of Log(625), base 5: ' + str(math.log(625, 5)))
print('The value of Log(1024), base 2: ' + str(math.log2(1024)))
print('The value of Log(1024), base 10: ' + str(math.log10(1024)))
The value of 5^8: 390625.0
Square root of 400: 20.0
The value of 5^e: 148.4131591025766
The value of Log(625), base 5: 4.0
The value of Log(1024), base 2: 10.0
The value of Log(1024), base 10: 3.010299956639812

These functions are used to calculate different trigonometric operations.
sin(x)
Return the sine of x in radians 
cos(x)
Return the cosine of x in radians
tan(x)
Return the tangent of x in radians
asin(x)
This is the inverse operation of the sine, there are acos, atan also.
degrees(x)
Convert angle x from radian to degrees
radians(x)
Convert angle x from degrees to radian
 Live Demo
import math
print('The value of Sin(60 degree): ' + str(math.sin(math.radians(60))))
print('The value of cos(pi): ' + str(math.cos(math.pi)))
print('The value of tan(90 degree): ' + str(math.tan(math.pi/2)))
print('The angle of sin(0.8660254037844386): ' + str(math.degrees(math.asin(0.8660254037844386))))
The value of Sin(60 degree): 0.8660254037844386
The value of cos(pi): -1.0
The value of tan(90 degree): 1.633123935319537e+16
The angle of sin(0.8660254037844386): 59.99999999999999