Standard Library Modules
Standard Library Modules
Python comes with many useful modules already installed.
You do not need to download them.
This collection is called the standard library.
What Is the Standard Library?
The standard library is a set of built-in modules that come with Python.
They help with:
- math
- dates
- random values
- files
- operating system tasks
- JSON
- CSV
- and much more
Why It Matters
Instead of writing everything yourself, you can use ready-made tools.
This saves time and effort.
Common Standard Library Modules
1. math
Used for math operations.
import math
print(math.sqrt(16))
print(math.pi)
Output
4.0
3.141592653589793
2. random
Used for random choices.
import random
print(random.randint(1, 10))
Example Output
7
(Output may be different.)
3. datetime
Used for dates and time.
from datetime import date
today = date.today()
print(today)
Example Output
2026-04-30
4. os
Used for folders and file paths.
import os
print(os.getcwd())
Example Output
/Users/student/project
5. json
Used for JSON files.
import json
data = {"name": "Tom"}
print(json.dumps(data))
Output
{"name": "Tom"}
6. csv
Used for CSV files.
import csv
How to Explore Modules
Use:
dir(math)
This shows items inside the module.
Common Beginner Tip
You do not need to memorize every module.
Learn how to search documentation and use what you need.
Code Along
Import random.
Print a random number from 1 to 5.
Mini Challenge
Use:
mathrandom
Tasks:
- Print square root of 81
- Print random number from 1 to 3
Expected output example:
9.0
2
Real World Use Case
Developers use the standard library daily for automation, dates, math, files, reports, and data processing.
Quiz
- What is the standard library?
- Which module helps with dates?
- Which module helps with random values?
- Which module helps with JSON?
Assignment
Use three different standard library modules in one small program.
Summary
You learned that Python includes many built-in modules that save time and solve common tasks.