Python comes with many built-in modules that provide useful functions and features. These modules can be used directly by importing them into your program.
math Module
The math module provides mathematical functions.
Example
import math
print(math.sqrt(25))
print(math.ceil(4.2))
print(math.floor(4.8))
Output:
5.0
5
4
random Module
The random module is used to generate random values.
Example
import random
print(random.randint(1, 10))
Output:
7
Output may vary each time.
datetime Module
The datetime module is used to work with dates and times.
Example
import datetime
current_date = datetime.datetime.now()
print(current_date)
Output:
2026-05-31 10:30:15.123456
Output will show the current date and time.
os Module
The os module provides functions for interacting with the operating system.
Example
import os
print(os.getcwd())
Output:
/home/user/project
Output will vary depending on your system.
sys Module
The sys module provides access to Python runtime information.
Example
import sys
print(sys.version)
Output:
3.13.0
Output may vary depending on the Python version installed.
statistics Module
The statistics module provides statistical functions.
Example
import statistics
numbers = [10, 20, 30, 40]
print(statistics.mean(numbers))
Output:
25
calendar Module
The calendar module is used to display calendars.
Example
import calendar
print(calendar.month(2026, 5))
Output:
May 2026
Mo Tu We Th Fr Sa Su
...
collections Module
The collections module provides specialized container data types.
Example
from collections import Counter
data = ["apple", "banana", "apple"]
print(Counter(data))
Output:
Counter({'apple': 2, 'banana': 1})
Summary
- Built-in modules come with Python.
mathprovides mathematical functions.randomgenerates random values.datetimeworks with dates and times.osinteracts with the operating system.sysprovides Python runtime information.statisticsperforms statistical calculations.calendardisplays calendar data.collectionsprovides advanced data structures.