Math Module in Python are the various modules made in Python for performing useful mathematical operations and complex expressions quite easily, also, without the usual hassles of a complex calculation. These are particularly useful when you have the theory. But, need to use the standard math tricks for your problem. Thus, this math module in Python has many varied and vivid features. Also, there are various functions present in this library and here, I will be bringing out most of them to you.

We thus, need to now know that to perform any mathematical operation in Python we just need to import the “math” module in Python and get our work done by using its various functions.

## Various Functions and the task they perform

#### Some Example Codes

``````import math

print('The Ceiling and the Floor value of 18.92 are: ' + str(math.ceil(23.56)) + ', ' + str(math.floor(23.56)))

print('Absolute value of -96 and 56 are: ' + str(math.fabs(-96)) + ', ' + str(math.fabs(56)))

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')``````

#### Output

```The Ceiling and the Floor value of 18.92 are: 19, 18

Absolute value of -106 and 36 are: 106.0, 36.0

The GCD of 24 and 56 : 8

It is not a number

It is Infinity```

#### Example Code

```import math
print('The value of 5^7 is : ' + str(math.pow(5, 8)))
print('Square root of 1600: ' + str(math.sqrt(1600)))
print('The value of 5^e: ' + str(math.exp(5)))
print('The value of Log(125), base 5: ' + str(math.log(125, 5)))
print('The value of Log(512), base 2: ' + str(math.log2(512)))
print('The value of Log(1024), base 10: ' + str(math.log10(1024)))

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))))```

#### Output

```The value of 5^7 is : 78125.0
Square root of 1600: 40.0
The value of 5^e: 148.4131591025766
The value of Log(625), base 5: 2.0
The value of Log(512), base 2: 9.0
The value of Log(1024), base 10: 3.010299956639812

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```

Thus, from these examples we have seen the various functionalities we can perform. Also, all by using these functions present in the math module in Python. We thus, just simply need to import the math library by using the import math option in Python and we are good to go. And, thus, perform complex mathematical computations and other operations. Lets see another miscellaneous example concerning this, the factorial function.

``````def fact(n):
if n < 0:
return 0
if n == 0:
return 1

factorial = 1
for i in range(1, n + 1):
factorial = factorial * i
return factorial``````

## SUMMING UP — Math Module in Python

So, in this post, we got hold of using the math module in Python. We also saw the various functionalities provided by the math library like sin, cos, tan functions and many more. All these functionalities also, have been demonstrated with the help of ample number of examples.