20. Commonly used modules

The sections below discuss only a tiny fraction of the official and unofficial module library of Python. For a full set, find the online and printed versions of the Python Library Reference Library Reference at the Python documentation site.

If you want to use any of these modules, you must import them. See the `import` statement and the `from` statement above.

20.1. The `math` module

This module provides the usual basic transcendental mathematical functions. All trig functions use angles in radians. The module has two members:

 `pi` The constant 3.14159... `e` The base of natural logarithms, 2.71828...

Functions in this module include:

 `acos(x)` Angle (in radians) whose cosine is `x`, that is, arccosine of `x`. `asin(x)` Arcsine of `x`. `atan(x)` Arctangent of `x`. `atan2(y,x)` Angle whose slope is `y/x`, even if `y` is zero. `ceil(x)` True ceiling function; `ceil(3.9)` yields 4.0, while `ceil(-3.9)` yields -3.0. `cos(x)` Cosine of `x`, where `x` is expressed in radians. `cosh(x)` Hyperbolic cosine of `x`. `exp(x)` `e` to the `x` power. `floor(x)` True floor function; `floor(3.9)` is 3.0, and `floor(-3.9)` is -4.0. `frexp(x)` Given a float `x`, returns a tuple `(m,e)` where `m` is the mantissa and `e` the binary exponent of `x`, and `x` is equal to `m * (2**e)`. If `x` is zero, returns the tuple ```(0.0, 0)```. `fmod(x,y)` `(x-int(x/y)*y)` `ldexp(x, i)` Returns `x * (2**i)`. `hypot(x,y)` The square root of (`x`2+`y`2). `log(x)` Natural log of `x`. `log10(x)` Common log (base 10) of `x`. `modf(x)` Returns a tuple ```(f, i)``` where `f` is the fractional part of `x`, `i` is the integral part (as a float), and both have the same sign as `x`. `sin(x)` Sine of `x`. `sinh(x)` Hyperbolic sine of `x`. `sqrt(x)` Square root of `x`. `tan(x)` Tangent of `x`. `tanh(x)` Hyperbolic tangent of `x`.