Python Mathematical Functions#
Learn about all the mathematical functions available in Python and how you can use them in your program.
What is math
module in Python?#
The math
module is a standard module in Python and is always available. To use mathematical functions under this module, you have to import the module using import math
.
It gives access to the underlying C library functions. For example:
# Square root calculation
import math
math.sqrt(4)
2.0
This module does not support complex datatypes. The cmath module is the complex
counterpart.
Functions in Python Math Module#
Here is the list of all the functions and attributes defined in math
module with a brief explanation of what they do.
List of Functions in Python Math Module
Function |
Description |
---|---|
|
Returns the smallest integer greater than or equal to x. |
|
Returns x with the sign of y |
|
Returns the absolute value of x |
|
Returns the factorial of x |
|
Returns the largest integer less than or equal to x |
|
Returns the remainder when x is divided by y |
|
Returns the mantissa and exponent of x as the pair (m, e) |
|
Returns an accurate floating point sum of values in the iterable |
|
Returns True if x is neither an infinity nor a NaN (Not a Number) |
|
Returns True if x is a positive or negative infinity |
|
Returns True if x is a NaN |
|
Returns x * (2**i) |
|
Returns the fractional and integer parts of x |
|
Returns the truncated integer value of x |
|
Returns e**x |
|
Returns e**x - 1 |
|
Returns the logarithm of |
|
Returns the natural logarithm of 1+x |
|
Returns the base-2 logarithm of x |
|
Returns the base-10 logarithm of x |
|
Returns x raised to the power y |
|
Returns the square root of x |
|
Returns the arc cosine of x |
|
Returns the arc sine of x |
|
Returns the arc tangent of x |
|
Returns atan(y / x) |
|
Returns the cosine of x |
|
Returns the Euclidean norm, sqrt(xx + yy) |
|
Returns the sine of x |
|
Returns the tangent of x |
|
Converts angle x from radians to degrees |
|
Converts angle x from degrees to radians |
|
Returns the inverse hyperbolic cosine of x |
|
Returns the inverse hyperbolic sine of x |
|
Returns the inverse hyperbolic tangent of x |
|
Returns the hyperbolic cosine of x |
|
Returns the hyperbolic cosine of x |
|
Returns the hyperbolic tangent of x |
|
Returns the error function at x |
|
Returns the complementary error function at x |
|
Returns the Gamma function at x |
|
Returns the natural logarithm of the absolute value of the Gamma function at x |
|
Mathematical constant, the ratio of circumference of a circle to itβs diameter (3.14159β¦) |
|
mathematical constant e (2.71828β¦) |
Visit this page to learn about all the mathematical functions defined in Python 3.