Python · Stage 8 – Organizing Bigger Programs · Lesson 41 of 50

Modules and Imports

Reuse code from another Python file through one explicit import.

Python includes a module named math:

import math
Line-by-line explanation
  1. import tells Python to load a module.
  2. math is the module name.
  3. Its tools are now available through that name.
answer = math.sqrt(25)
Line-by-line explanation
  1. math. selects something from the module.
  2. sqrt calculates a square root.
  3. answer stores 5.0.