SwadhyAI Notes

All Python notes

Python Math Module ➗

Math Module

Python has a built-in module that you can use for mathematical tasks.

✨ Common Math Methods

MethodDescription
acos()Returns the arc cosine of a number
acosh()Returns the inverse hyperbolic cosine of a number
asin()Returns the arc sine of a number
asinh()Returns the inverse hyperbolic sine of a number
atan()Returns the arc tangent of a number in radians
atan2()Returns the arc tangent of y/x in radians
atanh()Returns the inverse hyperbolic tangent of a number
ceil()Rounds a number up to the nearest integer
comb()Returns the number of ways to choose k items from n items without repetition and order
copysign()Returns a float consisting of the value of the first parameter and the sign of the second parameter
cos()Returns the cosine of a number
cosh()Returns the hyperbolic cosine of a number
degrees()Converts an angle from radians to degrees
dist()Returns the Euclidean distance between two points (p and q), where p and q are the coordinates of that point
erf()Returns the error function of a number
erfc()Returns the complementary error function of a number
exp()Returns E raised to the power of x
expm1()Returns E raised to the power of x, minus 1
fabs()Returns the absolute value of a number
factorial()Returns the factorial of a number
floor()Rounds a number down to the nearest integer
fmod()Returns the remainder of x/y
frexp()Returns the mantissa and the exponent, of a specified number
fsum()Returns the sum of all items in any iterable (tuples, arrays, lists, etc.)
gamma()Returns the gamma function at x
gcd()Returns the greatest common divisor of two integers
hypot()Returns the Euclidean norm
isclose()Checks whether two values are close to each other, or not
isfinite()Checks whether a number is finite or not
isinf()Checks whether a number is infinite or not
isnan()Checks whether a value is NaN (not a number) or not
isqrt()Rounds a square root number downwards to the nearest integer
ldexp()Returns the inverse of frexp() which is x * (2**i) of the given numbers x and i
lgamma()Returns the natural logarithm of the gamma function at x
log()Returns the natural logarithm of a number, or the logarithm of number to base
log10()Returns the base-10 logarithm of x
log1p()Returns the natural logarithm of 1+x
log2()Returns the base-2 logarithm of x
perm()Returns the number of ways to choose k items from n items with order and without repetition
pow()Returns the value of x to the power of y
prod()Returns the product of all the elements in an iterable
radians()Converts a degree value into radians
remainder()Returns the closest value that can make x completely divisible by y
sin()Returns the sine of a number
sinh()Returns the hyperbolic sine of a number
sqrt()Returns the square root of a number
tan()Returns the tangent of a number
tanh()Returns the hyperbolic tangent of a number
trunc()Returns the truncated integer parts of a number

💡 Did You Know?

The math module also defines two mathematical constants: math.pi and math.e.