Python math Module Functions

About This Index
This page is the Python math Module Functions index for the tutorial track. Each row links to a full guide with syntax, parameters, return type, error rules, three runnable scripts, and FAQs.
Start with the math module hub for imports, constants, float precision traps, and comparisons with built-in functions. Use this page to jump straight to sqrt(), isclose(), floor(), or gcd().
Always run import math before calling math.*. Most functions return a float, while integer helpers such as ceil(), floor(), isqrt(), gcd(), and comb() return an int. Newer additions such as cbrt()/exp2() (3.11), sumprod() (3.12), fma() (3.13), and recent additions like fmax() note their Python version inside each guide.
How to Call a math Function
Import math at the top of your script and call functions through the module name:
import math
print(math.sqrt(16)) # 4.0
print(math.floor(-2.5)) # -3
print(math.gcd(12, 18)) # 6
print(math.degrees(math.pi)) # 180.0
print(math.isclose(0.1 + 0.2, 0.3)) # True Python math Module Constants
Five ready-to-use constants live alongside the functions in math:
| Constant | Type | Meaning |
|---|---|---|
math.pi | float | Ratio of circumference to diameter, approximately 3.141592653589793. |
math.e | float | Euler's number, base of the natural logarithm, approximately 2.718281828459045. |
math.tau | float | Circle constant equal to 2 * pi, approximately 6.283185307179586 (Python 3.6+). |
math.inf | float | Floating-point positive infinity, equivalent to float("inf") (Python 3.5+). |
math.nan | float | Floating-point Not a Number, equivalent to float("nan") (Python 3.5+). |
Python math Functions Table
All 62 function guides in the math module, grouped by purpose.
Powers, roots, and distances
6 functionsSquare and cube roots, exact integer roots, float exponentiation, and Euclidean norms or point distances.
| Function | Returns | Description | Tutorial |
|---|---|---|---|
sqrt() | float | Return the square root of x as a float. | Try it |
cbrt() | float | Return the real cube root of x as a float (Python 3.11+). | Try it |
isqrt() | int | Return the integer square root of a non-negative integer. | Try it |
pow() | float | Raise x to power y and return a float. | Try it |
hypot() | float | Return the Euclidean norm sqrt(sum(x*x)) without overflow. | Try it |
dist() | float | Return the Euclidean distance between two points p and q. | Try it |
Exponentials and logarithms
7 functionsBase-e, base-2, and base-10 powers and logs, plus high-precision helpers for values near zero.
| Function | Returns | Description | Tutorial |
|---|---|---|---|
exp() | float | Return e raised to the power x as a float. | Try it |
exp2() | float | Return 2 raised to the power x as a float (Python 3.11+). | Try it |
expm1() | float | Return exp(x) - 1 accurately for values near zero. | Try it |
log() | float | Return the natural logarithm, or logarithm to a given base. | Try it |
log2() | float | Return the base-2 logarithm of x as a float. | Try it |
log10() | float | Return the base-10 logarithm of x as a float. | Try it |
log1p() | float | Return the natural logarithm of 1 + x accurately near zero. | Try it |
Trigonometry and angle conversion
9 functionsSine, cosine, tangent, inverse trig functions (including quadrant-aware atan2), and degree/radian helpers.
| Function | Returns | Description | Tutorial |
|---|---|---|---|
sin() | float | Return the sine of x radians as a float. | Try it |
cos() | float | Return the cosine of x radians as a float. | Try it |
tan() | float | Return the tangent of x radians as a float. | Try it |
asin() | float | Return the arc sine (inverse sine) of x in radians. | Try it |
acos() | float | Return the arc cosine (inverse cosine) of x in radians. | Try it |
atan() | float | Return the arc tangent (inverse tangent) of x in radians. | Try it |
atan2() | float | Return atan(y / x) in radians using signs of both arguments. | Try it |
degrees() | float | Convert angle x from radians to degrees. | Try it |
radians() | float | Convert angle x from degrees to radians. | Try it |
Hyperbolic functions
6 functionsHyperbolic sine, cosine, tangent, and their inverses for catenaries, rapidities, and smooth scaling.
| Function | Returns | Description | Tutorial |
|---|---|---|---|
sinh() | float | Return the hyperbolic sine of x as a float. | Try it |
cosh() | float | Return the hyperbolic cosine of x as a float. | Try it |
tanh() | float | Return the hyperbolic tangent of x as a float. | Try it |
asinh() | float | Return the inverse hyperbolic sine of x as a float. | Try it |
acosh() | float | Return the inverse hyperbolic cosine of x >= 1 as a float. | Try it |
atanh() | float | Return the inverse hyperbolic tangent of x in (-1, 1) as a float. | Try it |
Rounding, signs, and remainders
10 functionsCeiling, floor, truncation, float absolute value, sign copying, modulo variants, splitting fractional parts, and NaN-ignoring min/max.
| Function | Returns | Description | Tutorial |
|---|---|---|---|
ceil() | int | Return the ceiling of x, the smallest integer >= x. | Try it |
floor() | int | Return the floor of x, the largest integer <= x. | Try it |
trunc() | int | Truncate x toward zero to an integer. | Try it |
fabs() | float | Return the absolute value of x as a float. | Try it |
copysign() | float | Return a float with the magnitude of x and sign of y. | Try it |
fmod() | float | Return floating-point remainder keeping the sign of x. | Try it |
remainder() | float | Return the IEEE 754 remainder of x with respect to y. | Try it |
modf() | (float, float) | Return the fractional and integer parts of x as floats. | Try it |
fmax() | float | Return the larger of x and y as a float, ignoring a single NaN. | Try it |
fmin() | float | Return the smaller of x and y as a float, ignoring a single NaN. | Try it |
Number theory, counting, and accurate sums
9 functionsGreatest common divisor, least common multiple, factorials, combinations, permutations, products, compensated sums, and fused multiply-add.
| Function | Returns | Description | Tutorial |
|---|---|---|---|
gcd() | int | Return the greatest common divisor of integer arguments. | Try it |
lcm() | int | Return the least common multiple of integer arguments (Python 3.9+). | Try it |
factorial() | int | Return n! as an exact integer for non-negative integer n. | Try it |
comb() | int | Return the number of ways to choose k items from n without order. | Try it |
perm() | int | Return the number of ordered k-permutations from n items. | Try it |
prod() | int or float | Multiply all numeric elements in an iterable starting from start=1. | Try it |
fsum() | float | Return an accurate floating-point sum of values in an iterable. | Try it |
sumprod() | int or float | Return the sum of products of values from two iterables (Python 3.12+). | Try it |
fma() | float | Return fused multiply-add (x * y) + z with a single rounding (Python 3.13+). | Try it |
Floating-point checks and special functions
15 functionsTolerance comparison, finite/inf/NaN/normal/subnormal/signbit checks, binary float decomposition and ULPs, plus error and gamma functions.
| Function | Returns | Description | Tutorial |
|---|---|---|---|
isclose() | bool | Return True if a and b are close within tolerances (Python 3.5+). | Try it |
isfinite() | bool | Return True if x is neither an infinity nor a NaN. | Try it |
isinf() | bool | Return True if x is positive or negative infinity. | Try it |
isnan() | bool | Return True if x is a NaN (not a number). | Try it |
isnormal() | bool | Return True if x is a finite, nonzero normal float. | Try it |
issubnormal() | bool | Return True if x is a nonzero subnormal (denormal) float. | Try it |
signbit() | bool | Return True if the IEEE 754 sign bit of x is set. | Try it |
frexp() | (float, int) | Return (mantissa, exponent) such that x == m * 2**e. | Try it |
ldexp() | float | Return x * (2**i) as a float, exact inverse of frexp(). | Try it |
nextafter() | float | Return the next floating-point value after x toward y. | Try it |
ulp() | float | Return the value of the least significant bit of float x (Python 3.9+). | Try it |
erf() | float | Return the Gauss error function at x as a float. | Try it |
erfc() | float | Return the complementary error function 1 - erf(x) accurately. | Try it |
gamma() | float | Return the Gamma function at x as a float. | Try it |
lgamma() | float | Return natural log of the absolute value of Gamma(x). | Try it |
Frequently Asked Questions
Start with math.acos()
Open the first guide in the index and explore the math module.
15 people found this page helpful
