Complete Python Notes (A to Z with
Data Science, ML, Web Dev,
Automation)
1. Introduction
Python is a versatile language widely used in data science, machine learning, web
development, and automation. Its simplicity, vast libraries, and community support make it
the #1 choice for professionals.
2. Core Python (Recap)
Covers Variables, Data Types, Operators, Control Flow, Functions, File Handling, OOP, Error
Handling, etc.
3. Data Science with Python
NumPy (Numerical Python)
import numpy as np
arr = np.array([1,2,3,4])
print(arr.mean()) # Average
print(arr.shape) # Shape of array
print(np.arange(0,10,2)) # Range array
Pandas
import pandas as pd
data = {"Name":["Ali","Sara"], "Age":[25,30]}
df = pd.DataFrame(data)
df.to_csv("data.csv", index=False)
df2 = pd.read_csv("data.csv")
print(df.describe())
print(df.head())
Visualization (Matplotlib & Seaborn)
import matplotlib.pyplot as plt
import seaborn as sns
plt.plot([1,2,3],[4,5,6])
plt.show()
sns.barplot(x="Name", y="Age", data=df)
4. Machine Learning with Python
Workflow: Import Data → Preprocess → Train → Evaluate → Deploy
Example: Linear Regression
from sklearn.linear_model import LinearRegression
import numpy as np
X = np.array([[1],[2],[3]])
y = np.array([2,4,6])
model = LinearRegression()
model.fit(X,y)
print(model.predict([[4]]))
Common Algorithms:
Supervised → Linear Regression, Logistic Regression, Decision Trees, SVM, Random
Forest, XGBoost
Unsupervised → KMeans, PCA, Clustering
Deep Learning → TensorFlow, PyTorch
5. Web Development with Python
Flask (Lightweight)
from flask import Flask
app = Flask(__name__)
@app.route("/")
def home():
return "Hello Flask"
if __name__ == "__main__":
app.run(debug=True)
Django (Full-featured)
django-admin startproject myproject
python manage.py runserver
MTV architecture (Model, Template, View)
Built-in ORM, Admin panel, Authentication
6. Automation with Python
OS Automation
import os
print(os.listdir()) # List files
os.rename("old.txt","new.txt")
Web Scraping (BeautifulSoup)
import requests
from bs4 import BeautifulSoup
url = "https://example.com"
res = requests.get(url)
soup = BeautifulSoup(res.text, "html.parser")
print(soup.title.text)
Browser Automation (Selenium)
from selenium import webdriver
driver = webdriver.Chrome()
driver.get("https://google.com")
driver.find_element("name","q").send_keys("Python")
Task Scheduling
import schedule, time
def job():
print("Running task...")
schedule.every(5).seconds.do(job)
while True:
schedule.run_pending()
time.sleep(1)
7. Professional Practices
Write modular & reusable code
Follow PEP8 style guide
Use virtual environments (venv, conda)
Optimize with comprehensions & built-ins
Write unit tests (pytest, unittest)
Use logging instead of print
8. Pro Programmer Mindset
Prefer Pythonic solutions (list comprehension > manual loop)
Use optimized libraries (NumPy, Pandas, SQLAlchemy, etc.)
Automation mindset → script repetitive tasks
Write clean, maintainable, and scalable code