Skip to content

Modules and the Standard Library

Programming Python Difficulty 1/5

Beginning of the lesson

Modules and the Standard Library

Reuse ready-made code with import

Big Idea: You do not have to write everything yourself! Python comes with a huge collection of ready-made code called the standard library. Each piece is a module, and you bring one into your program with the word import. It is like opening a toolbox full of tools someone already built for you.
By the end you will be able to:
  • explain what a module and the standard library are,
  • use import to bring in code others wrote,
  • use the math module (like math.sqrt and math.pi),
  • use the random module (like random.randint and random.choice).

1. What is a module?

A module is a file full of ready-made Python code — useful functions and values that someone already wrote and tested. The standard library is the big set of modules that comes with Python automatically. You do not download anything; it is already there.

To use a module, you write import and the module's name at the top of your program:

import math

print(math.sqrt(16))
print(math.pi)

Output:

4.0
3.141592653589793

Here import math brings in the math module. Then math.sqrt(16) asks the module for a square root, and math.pi gives us the value of pi. The dot (.) means "look inside math for this thing".

2. How import works

1 2 3 You write import math Python loads the module You call math.sqrt(), math.pi
You write import, Python loads the module, and now you can use its ready-made tools.

First you ask for a module with import. Python finds it in the standard library and loads it. After that, everything inside the module is ready for you to use, again and again.

Continue this lesson on YourAIZone

The full lesson has the complete explanation, worked examples, common mistakes, tests with instant checking and an AI tutor. Start right away as a guest, or create an account to keep your progress.

In the full lesson

  • The complete explanation
  • Worked examples
  • Common mistakes and how to avoid them
  • Test questions: 15
  • AI tutor that answers questions about the topic
  • Progress tracking for students, parents and teachers