🐍 Python Tutorial: Standard Library
Python ships with a powerful and extensive standard library. It provides modules and functions for file I/O, system operations, regular expressions, data persistence, math, networking, and more—no need to install third-party packages for many common tasks.
1. os
Provides functions for interacting with the operating system:
import os
print(os.name)
print(os.getcwd())
os.mkdir("new_folder")2. sys
Provides access to interpreter-specific variables and functions:
import sys
print(sys.version)
print(sys.argv)3. math
Offers access to mathematical functions and constants:
import math
print(math.sqrt(16))
print(math.pi)4. datetime
Supports working with dates and times:
from datetime import datetime
now = datetime.now()
print(now.strftime("%Y-%m-%d %H:%M:%S"))5. random
Used for generating pseudo-random numbers:
import random
print(random.randint(1, 10))
print(random.choice(["apple", "banana", "cherry"]))6. re
Provides tools for working with regular expressions:
import re
pattern = r"d+"
result = re.findall(pattern, "There are 24 apples and 17 bananas.")
print(result)7. json
Allows you to encode and decode data in JSON format:
import json
data = {"name": "Alice", "age": 30}
json_str = json.dumps(data)
print(json_str)
parsed = json.loads(json_str)
print(parsed["name"])