Like the from statement above, the
import statement gives your
program access to objects from external modules.
The general form is:
importM0,M1, ...
where each is the name of a module.Mi
However, unlike the from
statement, the import statement
does not add the objects to your local name space.
Instead, it adds the name of the module to your local
name space, and you can refer to items in that module
using the syntax
where M.name
is the name of the module and
M is
the name of the object.name
For example, there is a standard module named
math that contains a variable
named pi and a function named
sqrt(). If you import it using
import math
then you can refer to the variable as
math.pi and the function as
math.sqrt().
If instead you did this:
from math import *
then you could refer to them simply as
pi and sqrt().