Facebook Page Twitter Page LinkedIn Page
× Python Tutorial Python Advanced Python Resources Python Libraries


The Python has a number of methods and functions that are available for mathematical operation. These methods and functions are listed below in alphabetical order. For more details about any one of these, please visit its page.

Python Math Functions
MethodDescription
ceil() Rounds the given number up to the nearest integer.
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.
gcd() Return the greatest common divisor of the specified arguments.
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).
ldexp() ldexp(a, b) returns a x 2b.
prod() Returns the product of all the elements in the input iterable.
nextAfter(x, y) Returns the floating point number adjacent to x in the direction of y
nextUp(x) Returns the floating point value adjacent to x in the direction of positive infinity
random() Returns a random number between 0 and 1
round(x) Returns the value of x rounded to its nearest integer
rint() Returns the double value that is closest to x and equal to a mathematical integer
signum(x) Returns the sign of x
remainder() Computes the remainder operation on two arguments as prescribed by the IEEE 754 standard.

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.

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 square root of sum of squares of two arguments, i.e., sqrt(x2 +y2).

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.

Constants

FunctionsDescription
pi Returns the value of 𝜋 to the available precision.
e Returns the value of e to the available precision.