Math Module
Built-in Math Functions
The min() and max() functions can be used to find the lowest or highest value in an iterable
Example 1
x = min(5, 10, 25)
x = max(5, 10, 25)
print(x)
print(y)
Output
5
25
abs()
The abs() function returns the absolute value of the specified number
Example 2
x = abs(-7.25)
print(x)
Output
7.25
pow(x,y)
The pow(x, y) function returns the value of x to the power of y.
Example
x = pow(4, 3)
print(x)
Output
64
Math Module
Python also has a built-in module called math, which extends the list of mathematical functions. In order to use it, the math module must be imported.
Example
import math
Math Module functions
Here is a list of all the Math module functions that can be used:
Method | Description |
---|---|
math.acos() | Returns the arc cosine of a number |
math.acosh() | Returns the inverse hyperbolic cosine of a number |
Math Module Constants
Constant | Description |
---|---|
math.e | Returns Euler's number (2.7182...) |
math.inf | Returns a floating-point positive infinity |