Chapter 5. Advanced Expressions
The math
and random
Modules, Bit-Level Operations, Division
A Python module extends the Python execution environment by adding
new classes, functions and helpful constants. We tell the Python
interpreter to fetch a module with a variation on the
import
statement. There are several variations on
import
, which we'll cover in depth in Part IV, “Components, Modules and Packages”.
For now, we'll use the simple
import
:
import m
This will import module m
. Only the module's
name, m
is made available. Every name inside the
module m
must be qualified
by prepending the module name and a .
. So if module
m
had a function called spam
,
we'd refer to it as m.spam
.
There are dozens of standard Python modules. We'll get to the most
important ones in Part IV, “Components, Modules and Packages”. For now, we'll focus on
extending the math capabilities of the basic expressions we've looked so
far.