python built in module


Python Built-in Modules simple example with result



Python Built-in Modules – Simple Examples with Results

Python provides many built-in modules that help us perform common tasks without installing external packages.

1. math Module

Used for mathematical operations.

import math

 

num = 25

 

print("Square root:", math.sqrt(num))

print("Power:", math.pow(2, 3))

print("Value of Pi:", math.pi)

Result:

Square root: 5.0

Power: 8.0

Value of Pi: 3.141592653589793


2. random Module

Used to generate random numbers.

import random

 

number = random.randint(1, 10)

 

print("Random number:", number)

Possible Result:

Random number: 7

The result can be different each time.


3. datetime Module

Used to work with dates and times.

import datetime

 

today = datetime.date.today()

 

print("Today's date:", today)

Result (example):

Today's date: 2026-10-03


4. os Module

Used to work with the operating system.

import os

 

print("Current folder:")

print(os.getcwd())

Result:

Current folder:

C:\Users\Student\Python

The result depends on where the Python program is running.


5. statistics Module

Used for basic statistical calculations.

import statistics

 

marks = [60, 70, 80, 90, 100]

 

print("Average:", statistics.mean(marks))

print("Median:", statistics.median(marks))

Result:

Average: 80

Median: 80


6. calendar Module

Used to display calendars.

import calendar

 

print(calendar.month(2026, 10))

Result:

    October 2026

Mo Tu We Th Fr Sa Su

          1  2  3  4

 5  6  7  8  9 10 11

12 13 14 15 16 17 18

19 20 21 22 23 24 25

26 27 28 29 30 31


7. sys Module

Used to get information about the Python system.

import sys

 

print("Python Version:")

print(sys.version)

Possible Result:

Python Version:

3.14.0 ...


Common Python Built-in Modules

Module

Main Use

Example

math

Mathematics

sqrt(), pow()

random

Random values

randint()

datetime

Date & time

date.today()

os

Operating system

getcwd()

statistics

Statistics

mean()

calendar

Calendar

month()

sys

Python system information

sys.version

json

JSON data

json.dumps()

re

Pattern matching

re.search()

time

Time-related functions

time.sleep()

Simple definition: A module is a Python file/library containing functions, classes, and variables that we can reuse in our programs using import.

Meet Codex in the desktop app

A coding agent that helps you build and ship with AI, included for free in your ChatGPT plan.

Download the app

Learn more

Top of Form

Bottom of Form

 


Comments

Popular posts from this blog

Python none

python random module