import sys sys.argv # Command-line arguments sys.version # Python version
math Module
Title
Concept
Code
Mathematical Functions and Constants
Advanced Math Operations, Constants like pi.
import math math.sqrt(16) # Calculate square root math.pi # Value of pi
datetime Module
Title
Concept
Code
Date and Time Operations
Working with Dates, Timezones.
import datetime datetime.datetime.now() # Current date and time datetime.timedelta(days=7) # Create a time delta
random Module
Title
Concept
Code
Generating Random Numbers
Random Number Generation, Seed Initialization.
import random random.randint(1, 100) # Generate random integer random.choice(['A', 'B', 'C']) # Random choice
Data Handling and Processing Modules
csv Module
Title
Concept
Code
Reading and Writing CSV Files
CSV Data Operations, Data Extraction.
import csv with open('data.csv') as file: csv_reader = csv.reader(file) data = [row for row in csv_reader]
json Module
Title
Concept
Code
JSON Data Serialization and Deserialization
JSON Data Handling, File I/O.
import json data = {'key': 'value'} json_text = json.dumps(data) # Serialize to JSON data = json.loads(json_text) # Deserialize from JSON
sqlite3 Module
Title
Concept
Code
SQLite Database Interaction
SQL Queries, Database Operations.
import sqlite3 conn = sqlite3.connect('example.db') c = conn.cursor() c.execute('SELECT * FROM table')
pickle Module
Title
Concept
Code
Object Serialization for Python Data Objects
Storing and Retrieving Objects, Data Persistence.
import pickle data = {'key': 'value'} with open('data.pkl', 'wb') as file: pickle.dump(data, file) with open('data.pkl', 'rb') as file: loaded_data = pickle.load(file)
Networking and Internet Modules
socket Module
Title
Concept
Code
Creating Client and Server Applications
Network Communication, Socket Programming.
import socket server_socket = socket.socket() # Create a server socket client_socket = socket.socket() # Create a client socket