🧰
Modules & Packages

Standard Library Highlights

os, sys, datetime, random
💡 Python ki standard library "batteries included" philosophy follow karti hai — bahut kuch already ready-made hai, external packages install kiye bina. os, datetime, random jaise modules "free tools" hain jo Python ke saath hi aate hain.

Kuch bahut common standard library modules: os (file system, environment variables), sys (interpreter-related, command-line args), datetime (dates/times), random (random numbers), math (mathematical functions), collections (Counter, deque, jo pehle dekha).

import os
print(os.getcwd())          # current directory
print(os.listdir("."))       # files in current directory

import datetime
now = datetime.datetime.now()
print(now.year, now.month, now.day)

import random
print(random.randint(1, 10))     # random int 1-10
print(random.choice(["a", "b", "c"]))   # random element

import math
print(math.sqrt(16))    # 4.0
print(math.pi)             # 3.14159...
🧰
Python ki standard library "batteries included" philosophy follow karti hai — bahut kuch already ready-made hai, external packages install kiye bina. os, datetime, random jaise modules "free tools" hain jo Python ke saath hi aate hain.
1 / 2
⚡ Quick Recap
  • os = file system operations, sys = interpreter/CLI related
  • datetime = dates/times, random = random values
  • "Batteries included" — bahut kuch pre-installed hai
On this page (2 subtopics)

re module pattern-matching (regex) deta hai — text validation, search, replace ke liye bahut powerful. Detail mein Advanced Python category mein aayega, yaha ek quick preview.

import re

text = "My email is aarav@example.com"
match = re.search(r"[\w.]+@[\w.]+", text)
if match:
    print(match.group())   # "aarav@example.com"
💡Tip: re module bahut powerful hai lekin regex patterns khud seekhna padta hai — Advanced Python category mein isko detail se cover karenge.

itertools module advanced iteration patterns deta hai — combinations, permutations, infinite counters, waghera. Data processing/algorithms mein bahut useful, especially combinatorics problems ke liye.

from itertools import combinations, permutations

items = ["A", "B", "C"]
print(list(combinations(items, 2)))   # [('A','B'), ('A','C'), ('B','C')]
print(list(permutations(items, 2)))    # all ordered pairs
💡Tip: itertools ka poora goal memory-efficiency hai — sab kuch lazy (generator-based) hai, bade combinatorial spaces ke liye bhi memory kam lagti hai.