English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

Python Basic Tutorial

Python Flow Control

Python Functions

Python Data Types

Python File Operations

Python Objects and Classes

Python Date and Time

Advanced Knowledge of Python

Python Reference Manual

Python Math Module (Math)

Understand all the mathematical functions available in Python and how to use them in programs.

What is the mathematical module in Python?

math Moduleis a standard module in Python and is always available. To use mathematical functions under this module, you must use the import module import math.

It provides access to basic C library functions. For example,

# Square root calculation
import math
math.sqrt(4)

This module does not support complex data types.CMATH moduleare complex correspondences.

Functions in the Python Math module

This is a list of all functions and attributes defined in the math module, with a brief explanation of their functions.

List of functions in the Python Math module
FunctionDescription
ceil(x)Returns the smallest integer greater than or equal to x
copysign(x, y)Returns x with the sign of y
fabs(x)Returns the absolute value of x
factorial(x)Returns the factorial of x
floor(x)Returns the largest integer less than or equal to x
fmod(x, y)Returns the remainder when x is divided by y
frexp(x)Returns the tail number and exponent of x as a pair (m, e)
fsum(iterable)Returns the exact floating-point value of the sum in the iterator
isfinite(x)If x is neither infinite nor NaN (not a number), then return True
isinf(x)If x is positive or negative infinity, return True
isnan(x)If x is NaN, return True
ldexp(x, i)Return x *(2 ** i)
modf(x)Return the fractional and integer parts of x
trunc(x)Return the truncated integer value of x
exp(x)Return e ** x
expm1(x)Return e ** x-1
log(x[, base])Return the logarithm of x to the base (default is e)
log1p(x)Return1 + The natural logarithm of x
log2(x)Return the logarithm of x to the base2Logarithm to the base
log10(x)Return the logarithm of x to the base10Logarithm to the base
pow(x, y)Return x to the power of y
sqrt(x)Return the square root of x
acos(x)Return the arccosine of x
asin(x)Return the arcsine of x
atan(x)Return the arctangent of x
atan2(y, x)Return atan(y / x)
cos(x)Return the cosine of x
hypot(x, y)Return the Euclidean norm sqrt(x * x + y * y)
sin(x)Return the sine of x
tan(x)Return the tangent of x
degrees(x)Convert the angle x from radians to degrees
radians(x)Convert the angle x from degrees to radians
acosh(x)Return the inverse hyperbolic cosine value at x
asinh(x)Return the inverse hyperbolic sine value at x
atanh(x)Return the inverse hyperbolic tangent value at x
cosh(x)Return the hyperbolic cosine value at x
sinh(x)Return the hyperbolic cosine value at x
tanh(x)Return the hyperbolic tangent at x
erf(x)Return the error function at x
erfc(x)Return the complementary error function at x
gamma(x)Return the Gamma function at x
lgamma(x)Return the natural logarithm of the absolute value of the Gamma function at x
piMathematical constant, the ratio of the circumference of a circle to its diameter (3.14159 ...)
eMathematical constant e (2.71828 ...)

Access this page to learn about Python 3All defined inMathematical functions.