Python has a set of built-in math functions, including an extensive math module, that allows you to perform mathematical tasks on numbers.
The min() and max() functions can be used to find the lowest or highest value in an iterable:
x = min(5, 10, 25) y = max(5, 10, 25) z = abs(-7.25) p = pow(4, 3) # 4 to the power of 3print("Min:", x) print("Max:", y) print("Absolute:", z) print("Power:", p)
math ModulePython has also a built-in module called math, which extends the list of mathematical functions. To use it, you must import math.
math.sqrt(): Returns the square root of a number.math.ceil(): Rounds a number upwards to its nearest integer.math.floor(): Rounds a number downwards to its nearest integer.math.pi: Returns the value of PI (3.14159...).import mathprint(math.sqrt(64)) # 8.0
print(math.ceil(1.4)) # 2 print(math.floor(1.4)) # 1
print(math.pi) # 3.141592653589793