Python Tutorial Python Advanced Python References Python Libraries

Python - Math Module



The Python has a math module which contains number of functions that are available for mathematical operation. The functions and constants of math module are listed below:

Python Math Functions

Basic Math Functions

MethodDescription
ceil() Rounds the given number up to the nearest integer.
comb() Returns the number of ways to choose k items from n items without repetition and without order.
copySign() Returns a number with magnitude of first argument and sign of second argument.
fabs() Returns the absolute value of a given number
factorial() Returns factorial of a given integer.
floor() Rounds the given number down to the nearest integer.
fmod() Computes the remainder operation on two arguments.
frexp() Returns the mantissa and exponent of the argument.
fsum() Returns an accurate floating point sum of values in the iterable.
gcd() Return the greatest common divisor of the specified arguments.
isclose() Check if two values are close to each other.
isfinite() Check if the argument is neither an infinity nor a NaN.
isinf() Check if the argument is positive or negative infinity.
isnan() Check if the argument is a NaN (not a number).
lcm() Return the least common multiple of the specified arguments.
ldexp() ldexp(a, b) returns a x 2b.
modf() Return the integral and fractional parts of a given number.
nextafter() Returns the next floating-point value after first argument towards second argument.
perm() Returns the number of ways to choose k items from n items without repetition and with order.
prod() Returns the product of all the elements in the input iterable.
remainder() Computes the remainder operation on two arguments as prescribed by the IEEE 754 standard.
trunc() Returns the truncated integer part of the argument.
ulp() Return the value of the least significant bit of the float argument.

Power & Logarithmic Functions

FunctionsDescription
exp() Returns the exponent of e.
expm1() Returns the exponent of e minus 1, i.e., ex-1.
log() Returns the natural logarithm of a given number.
log1p() Returns the natural logarithm of (1+number), i.e., log(1+number).
log2() Returns the base-2 logarithm of a given number.
log10() Returns the base-10 logarithm of a given number.
pow() Returns base raised to the power of exponent.
sqrt() Returns the square root of the given number.
isqrt() Returns the integer square root of the given number.

Trigonometric Functions

FunctionsDescription
sin() Returns the trigonometric sine of an angle in radians.
cos() Returns the trigonometric cosine of an angle in radians.
tan() Returns the trigonometric tangent of an angle in radians.
asin() Returns the arc sine of a value.
acos() Returns the arc cosine of a value.
atan() Returns the arc tangent of a value.
atan2() Returns the angle theta from the conversion of rectangular coordinates (x, y) to polar coordinates (r, theta).
hypot() Returns the length of the vector from the origin to the given point.
dist() Returns the Euclidean distance between two given points.

Hyperbolic Functions

FunctionsDescription
sinh() Returns the hyperbolic sine of a value.
cosh() Returns the hyperbolic cosine of a value.
tanh() Returns the hyperbolic tangent of a value.
asinh() Returns the inverse hyperbolic sine of a value
acosh() Returns the inverse hyperbolic cosine of a value
atanh() Returns the inverse hyperbolic tangent of a value

Angular Conversion

FunctionsDescription
degrees() Returns an angle measured in radians to an approx. equivalent angle measured in degrees.
radians() Returns an angle measured in degrees to an approx. equivalent angle measured in radians.

Special Functions

FunctionsDescription
erf() Returns the error function of the argument.
erfc() Returns the complementary error function of the argument.
gamma() Returns the gamma function of the argument.
lgamma() Returns the natural logarithm of the absolute value of the gamma function of the argument.

Constants

FunctionsDescription
pi Returns the value of 𝜋 to the available precision.
e Returns the value of e to the available precision.
tau Returns the value of Τ to the available precision.
inf Returns a floating-point positive infinity.
nan Returns a floating-point "not a number" (NaN) value.