Python Math Module
Published Jul 30, 2021Updated Sep 9, 2021
Contribute to Docs
Python has a built-in math module that we can use for mathematical tasks. This module provides access to the mathematical functions defined by the C standard.
The following functions are provided by this module. Except when explicitly noted otherwise, all return values are floats.
Math Module
- .asin()
- Returns the arcsine of a value, giving an angle in radians between `-π/2` and `π/2` for inputs ranging from `-1` to `1`
- .comb()
- Calculates the number of ways to choose `k` items from `n` items without regard to order or repetition.
- .isclose()
- Determines if two floating-point numbers are close to each other within a specified tolerance.
- math.acos()
- Returns the arc cosine of a number.
- math.acosh()
- Computes the inverse hyperbolic cosine of a number.
- math.asinh()
- Returns the inverse hyperbolic sine of a given number.
- math.atan()
- Returns the inverse tangent of a number.
- math.atan2()
- Returns the arc tangent of the quotient of its two arguments in radians.
- math.atanh()
- Returns the inverse hyperbolic tangent of a number.
- math.ceil()
- Takes in a numeric data type and rounds the value up to the nearest integer.
- math.copysign()
- Takes two numeric values and returns a float with the magnitude (absolute value) of the first value and the sign of the second value.
- math.cos()
- Returns the cosine of an angle.
- math.cosh()
- Computes the hyperbolic cosine function for a specified numeric input.
- math.degrees()
- Returns the degree equivalent of an input angle given in radians.
- math.erf()
- Returns the error function of a number.
- math.erfc()
- Finds the complementary error function of a number.
- math.exp()
- Returns e raised to the power of x.
- math.fabs()
- Computes the absolute value of a number and returns it as a floating-point value.
- math.factorial()
- Returns factorial of a number.
- math.floor()
- Returns the largest integer less than or equal to the input
- math.frexp()
- Returns the mantissa and the exponent of a given number as a tuple.
- math.fsum()
- Computes the precise floating-point sum of an iterable of numbers.
- math.gcd()
- Returns the Greatest Common Divisor (GCD) of two or more integers.
- math.isfinite()
- Checks whether a given number is finite or not.
- math.isinf()
- Returns a boolean indicating whether the given value is infinite or not.
- math.isnan()
- Returns a boolean indicating whether the given value is "Not a Number" (NaN).
- math.log()
- Returns the natural logarithm of a number or the logarithm of a number to the given base.
- math.pow()
- Returns the float value of x raised to the power of y.
- math.radians()
- Returns the radian equivalent of an input angle given in degrees.
- math.remainder()
- Returns the remainder of x divided by y
- math.sin()
- Returns the sine of input numeric x, measured in radian value.
- math.sqrt()
- Calculates the square root of a given number.
- math.tan()
- Returns the tangent of input numeric x, measured in radians.
Contribute to Docs
- Learn more about how to get involved.
- Edit this page on GitHub to fix an error or make an improvement.
- Submit feedback to let us know how we can improve Docs.
Learn Python on Codecademy
- Looking for an introduction to the theory behind programming? Master Python while learning data structures, algorithms, and more!
- Includes 6 Courses
- With Professional Certification
- Beginner Friendly.75 hours
- Front-end engineers work closely with designers to make websites beautiful, functional, and fast.
- Includes 34 Courses
- With Professional Certification
- Beginner Friendly.115 hours