Importing Modules
To gain access to the variables and functions from a module, you have to import it. To tell Python that you want to use functions in module math, for example, you use this import statement:
| >>> import math |
Importing a module creates a new variable with that name. That variable refers to an object whose type is module:
| >>> type(math) |
| <class 'module'> |
Once you have imported a module, you can use built-in function help to see what it contains. Here is the first part of the help output:
| >>> help(math) |
| |
| Help on module math: |
| |
| NAME |
| math |
| |
| MODULE REFERENCE |
| http://docs.python.org/3.3/library/math |
| |
| The following documentation is automatically generated from the Python |
| source files. It may ... |
Get Practical Programming, 2nd Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.