Introduction
Standard library modules help you do common tasks easily without writing code from scratch.
Jump into concepts and practice - no test required
Standard library modules help you do common tasks easily without writing code from scratch.
import module_name # Use functions or classes from the module like: module_name.function_name()
import to bring a module into your program.import math print(math.sqrt(16))
import random print(random.randint(1, 10))
date part from the datetime module and prints today's date.from datetime import date print(date.today())
This program shows how to use three standard library modules: math for square root, random for random numbers, and datetime for current date and time.
import math import random from datetime import datetime number = 25 root = math.sqrt(number) print(f"Square root of {number} is {root}") rand_num = random.randint(1, 100) print(f"Random number between 1 and 100: {rand_num}") now = datetime.now() print(f"Current date and time: {now}")
Standard library modules are already installed with Python, so you don't need to install anything extra.
Using these modules saves time and helps avoid errors.
You can find many useful modules in the official Python documentation.
Standard library modules provide ready-made tools for common tasks.
They help you write less code and avoid mistakes.
You use import to access these modules in your programs.
math or random?math module to calculate the square root of 16?import math allows access to functions with math.function_name().math.sqrt(16) after importing math.import random print(random.randint(1, 3))
random.randint(1, 3) returns a random integer including both 1 and 3.datetime module but causes an error:print(datetime.date.today())
datetime.date.today() without importing the datetime module, causing a NameError.import datetime at the top allows access to datetime.date.today().io module provides tools to open and read files easily in Python.os handles operating system tasks, sys deals with system-specific parameters, and re is for regular expressions, not file reading.