Python Math
Python has a set built-in math functions that provides access to mathematical functions for permorming tasks on numbers.
The min() and max() Math Function
The min() function is used to find the lowest number and the max() function is used to find the highest number.
Example
x = min(4,6,7,8,2)
y = max(4,6,7,8,2)
print(x)
print(y)
Output
8
The pow() Math Function
The pow() function is used to get the power of a varible x to the power of y.
Example
x = pow(5,3)
print(x)
Output
The abs() Math Function
The abs() function returns a non-negative value of a numeric value.
Example
x = abs(-55.34)
print(x)
Output
Math Module
Python has a built-in math module that extends the mathematical functionalities for permorming tasks on numbers.
Use Math Module
To use the math module, you will need to import it.
Example
import math
math.ceil()
The ceil() function rounds number up to its nearest integer number.
Example
import math
x = math.ceil(52.31)
print(x)
Output
math.floor()
The floor() function rounds number down to its nearest integer number.
Example
import math
x = math.floor(52.31)
print(x)
Output
math.sqrt()
The sqrt() function returns the square root a number.
Example
import math
x = math.sqrt(40)
print(x)