# Math Module in Python

For advanced math problems, we might have a hard time writing the code manually. Thankfully, we have the math module in python which solves complex mathematical problems for us

#### Built-in Functions

First, we’ll see some Built-in Math Functions, given to us in python

##### Max and Min

In order to find the lowest or highest value in a list, we use max and min functions.

This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
 list = [1, 2, 3, 4] a = max(list) b = min(list) print(a, b)
view raw math1.py hosted with ❤ by GitHub

OUTPUT:
`4,1`
##### Absolute value

Absolute value can be referred the distance of the number from zero

This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
 a = -2.43 print(abs(a))
view raw math2.py hosted with ❤ by GitHub

OUTPUT:
`2.43`

#### The Math Module

For advanced mathematics, python has created a package called math.
Let’s see it in action!

##### Square root

Here we are importing math and using it to find the square root of 64

This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
 import math a = 64 print(math.sqrt(a))
view raw math3.py hosted with ❤ by GitHub

OUTPUT:
`6`
##### Factorial

Factorial means the product of all positive numbers less than or equal to the number for which we want
to find the factorial

This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
 import math print(math.factorial(3))
view raw math4.py hosted with ❤ by GitHub

OUTPUT:
`6`
##### Trigonometry

We can also use the math module in Trignometry.

This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
 import math a = 22 # radians print(math.sin(a))
view raw math5.py hosted with ❤ by GitHub

OUTPUT:
`-0.00885`

Here we are able to find the sin for an angle of 22 in radians. #### Aniket Malik

Oracle Certified Tutor/Trainer with 100+ reviews 