Skip to the content.
24 August 2026

Python is famous for its “batteries included” philosophy. This means that the standard library comes packed with utilities to handle common tasks right out of the box, saving you from installing third-party dependencies.

As a beginner, getting familiar with these built-in tools will make your code shorter and more reliable.

The math module

For basic arithmetic, Python has standard operators like + and *. But if you need trigonometric functions, logarithms, or constants like pi, you should use the math module.

import math

# Calculate the area of a circle with radius 5
area = math.pi * (5 ** 2)
print(area)

The math module is highly optimized, making it much faster than writing custom mathematical approximations.

The random module

If you are building a game or simulating data, you often need some randomness. The random module provides utilities for generating random numbers and selecting random items from lists.

import random

# Generate a random integer between 1 and 10
number = random.randint(1, 10)

# Pick a random element from a list
choices = ["rock", "paper", "scissors"]
computer_move = random.choice(choices)

For security purposes like generating passwords, Python has a separate module named secrets because random generates pseudo-random numbers that are predictable if someone knows the generator’s state.

The datetime module

Dealing with dates and times is notoriously tricky because of time zones, leap years, and different calendar formats. The datetime module helps you parse, format, and calculate time differences.

from datetime import datetime, timedelta

# Get the current local time
now = datetime.now()

# Add exactly seven days to the current date
next_week = now + timedelta(days=7)

Using timedelta makes it straightforward to build schedules or expire user sessions without worrying about calendar math.

The json module

Most web APIs exchange data using JSON. Python’s built-in json module makes it simple to convert Python dictionaries to JSON strings, or parse JSON strings back into dictionaries.

import json

# Convert a Python dictionary to a JSON string
user_data = {"name": "Alex", "age": 28}
json_string = json.dumps(user_data)

Using the standard library means your JSON parsing is secure and fast.

Try it yourself

You do not need to set up Python on your computer to practice using these modules. You can write and run your Python scripts instantly in our web-based Python playground. Just import any standard module and see how it works in real time. For a handy syntax reference, see our Python Cheatsheet.