Python math Module
Example
Compute a square root and print Pi:
import math
print(math.sqrt(16))
print(math.pi)
Try it Yourself »
Definition and Usage
The math module provides mathematical functions like trigonometry, logarithms, and constants.
Use it for accurate floating-point operations and convenient helpers such as factorial, sqrt, and hypot.
Members
Member | Description |
---|---|
acos() | Return the arc cosine of x, in radians. |
asin() | Return the arc sine of x, in radians. |
atan() | Return the arc tangent of x, in radians. |
atan2() | Return atan(y / x), in radians. |
ceil() | Return the ceiling of x (smallest integer >= x). |
cos() | Return the cosine of x radians. |
degrees() | Convert angle x from radians to degrees. |
e | Mathematical constant e (2.718...). |
exp() | Return e raised to the power x. |
factorial() | Return x! as an exact integer. |
floor() | Return the floor of x (largest integer <= x). |
hypot() | Return the Euclidean norm, sqrt(x*x + y*y). |
inf | Floating-point positive infinity. |
isfinite() | Return True if x is neither infinite nor NaN. |
isinf() | Return True if x is a positive or negative infinity. |
isnan() | Return True if x is a NaN (not a number). |
log() | Return the natural logarithm of x. |
log10() | Return the base-10 logarithm of x. |
nan | Floating-point "not a number" (NaN). |
pi | Mathematical constant π (3.14159...). |
pow() | Return x raised to the power y. |
radians() | Convert angle x from degrees to radians. |
sin() | Return the sine of x radians. |
sqrt() | Return the square root of x. |
tan() | Return the tangent of x radians. |
trunc() | Return x truncated to an integer. |