Skip to main content

Imports & Your Own Modules

beginner12 min readLesson 36 of 169

import vs from-import, prefix discipline, and any .py file is a module.

An import makes code from another file available in yours:

import math

print(math.sqrt(144))    # 12.0 โ€” note the module NAME prefix

The prefix is the point: every use shows where the function came from. from import copies specific names out:

from math import sqrt

print(sqrt(144))         # 12.0 โ€” no prefix, but the origin is less visible

For a beginner, prefer plain import math: readers can trace every name, and imports at the top of the file form a table of contents. Reserve from import for long module names or very frequent use.

Now practice

Import & Module DrillsPrefix discipline and the __main__ guard.3 challenges ยท ยท ~25 min