1. Importing Libraries
Use import to access libraries. Standard library (built-in) vs external (pip install).
import math
import random
from datetime import datetime
print(math.pi) # 3.14159...
print(random.randint(1, 10)) # Random number
print(datetime.now())
3.141592653589793
7
2025-11-29 22:37:00.123456
2. math - Mathematical Functions
Advanced math operations beyond basic operators.
import math
print(math.sqrt(16)) # 4.0
print(math.ceil(3.2)) # 4
print(math.floor(3.7)) # 3
print(math.pow(2, 3)) # 8.0
4.0
4
3
8.0
3. random - Random Numbers & Choices
Generate random numbers, shuffle lists, pick random items.
import random
numbers = [1, 2, 3, 4, 5]
print(random.choice(numbers)) # Random item
print(random.randint(1, 10)) # 1-10
random.shuffle(numbers)
print(numbers) # Shuffled
[3, 1, 5, 2, 4]
7
[3, 1, 5, 2, 4]
4. datetime - Date & Time
Handle dates, times, timestamps easily.
from datetime import datetime, timedelta
now = datetime.now()
print(now.strftime("%Y-%m-%d %H:%M")) # Format date
yesterday = now - timedelta(days=1)
print(yesterday.strftime("%B %d, %Y"))
2025-11-29 22:37
November 28, 2025
5. os & json - File Operations
Interact with files and directories.
import os
import json
# List files
print(os.listdir(".")[:3]) # First 3 files
# JSON example
data = {"name": "Python", "version": 3.11}
json_str = json.dumps(data)
print(json_str)
['index.html', 'styles.css', 'script.js']
{"name": "Python", "version": 3.11}
Most Popular Libraries Reference
| Library | Install | Main Use | Example |
|---|---|---|---|
| numpy | pip install numpy | Arrays/Math | import numpy as np |
| pandas | pip install pandas | Data Analysis | import pandas as pd |
| matplotlib | pip install matplotlib | Plotting | plt.plot() |
| requests | pip install requests | HTTP | requests.get() |
| flask | pip install flask | Web Apps | app.route() |
๐ง Libraries Quiz (8 Questions)
Q1: Import specific function?
Q2: Random integer 1-10?
Q3: Math square root?
Q4: Current date/time module?
Q5: List current directory?
Q6: Data analysis library?
Q7: Web requests library?
Q8: JSON to string?