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 float
s.
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.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()
- Returns the hyperbolic cosine of a number.
- 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()
- Takes in a numeric data type and rounds the value down to the nearest integer.
- 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()
- Returns the square root of numeric input x.
- 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.