math
The math module provides common mathematical functions and constants.
Constants
These are properties, accessed without parentheses:
| Property | Value |
|---|---|
math.pi |
3.141592653589793 |
math.e |
2.718281828459045 |
math.inf |
Positive infinity |
You can also import them directly:
Functions
math.sqrt(x)
Returns the square root of x. Accepts int or float.
math.abs(x)
Returns the absolute value. Accepts int or float, returns the same type.
math.floor(x)
Rounds down to the nearest integer. Returns int.
math.ceil(x)
Rounds up to the nearest integer. Returns int.
math.round(x)
Rounds to the nearest integer. Returns int.
math.pow(base, exp)
Returns base raised to the power of exp.
math.sin(x), math.cos(x), math.tan(x)
Trigonometric functions. Argument is in radians.
math.log(x), math.log10(x)
Natural logarithm and base-10 logarithm.
math.min(a, b), math.max(a, b)
Returns the smaller or larger of two values. Accepts int or float.