๐ Python Programming โ Complete Learning Repository
๐ A complete structured Python programming repository covering
fundamentals to advanced concepts โ from data types and loops to
OOP, decorators, exception handling, file I/O, FastAPI Routers,
HTTP Methods, and AI API integration.
Lecture
Topic
Lecture 04 (Part 1)
Python Basics โ Variables, Strings, Input
Lecture 04 (Part 2)
Python Data Types โ int, float, list, dict, tuple, set
Lecture 05
Operators โ Arithmetic, Comparison, Logical, Assignment
Lecture 06
Loops โ for, while, nested loops, break, continue
Lecture 07
Conditional Statements โ if, elif, else
Lecture
Topic
Lecture 08
Introduction to Functions & Built-in Functions
Lecture 09
User Defined Functions โ def, return, arguments
Lecture 09 (Final)
User Defined Functions โ advanced examples
Lecture 10
Local vs Global Scope ยท is vs ==
Lecture 11
Higher Order Functions โ map, filter, lambda
Lecture 12
Decorators in Python
Lecture 22
Required and Optional Parameters
๐ก๏ธ Error Handling & File I/O
Lecture
Topic
Lecture 13
File Handling & JSON โ read, write, parse
Lecture 14
Exception Handling โ try, except, finally
๐๏ธ Object Oriented Programming
Lecture
Topic
Lecture 16
OOP Basics โ Classes, Objects, Methods, Exercises
โก FastAPI & Web Development
Lecture
Topic
intro_to_fastapi_basic.ipynb
FastAPI Introduction โ building first REST API
Lecture 23
FastAPI Routers โ HTTP Methods, Path & Query Parameters, APIRouter
Lecture 24
HTTP Methods Deep Dive โ GET, POST, PUT, DELETE, Modular API Design
File
Topic
intro_to_ai_apis.ipynb
AI API Integration โ calling LLMs from Python
๐ Assignments & Practice
File
Description
Assignment_01.ipynb
Python fundamentals practice
Assignment_02.ipynb
Functions & control flow exercises
Practice_Lec_01.ipynb
Hands-on practice notebook
๐ก Key Concepts with Code Examples
import time
def timer (func ):
def wrapper (* args , ** kwargs ):
start = time .time ()
result = func (* args , ** kwargs )
end = time .time ()
print (f"{ func .__name__ } ran in { end - start :.4f} s" )
return result
return wrapper
@timer
def slow_function ():
time .sleep (1 )
return "Done!"
slow_function ()
# Output: slow_function ran in 1.0012s
๐ท Higher Order Functions
numbers = [1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 , 10 ]
# map โ apply function to each element
squared = list (map (lambda x : x ** 2 , numbers ))
# filter โ keep elements matching condition
evens = list (filter (lambda x : x % 2 == 0 , numbers ))
# lambda โ anonymous function
multiply = lambda x , y : x * y
print (multiply (3 , 4 )) # 12
๐ท OOP โ Classes & Objects
class BankAccount :
def __init__ (self , owner , balance = 0 ):
self .owner = owner
self .__balance = balance # private attribute
def deposit (self , amount ):
self .__balance += amount
return f"Deposited { amount } . Balance: { self .__balance } "
def withdraw (self , amount ):
if amount > self .__balance :
raise ValueError ("Insufficient funds!" )
self .__balance -= amount
@property
def balance (self ):
return self .__balance
acc = BankAccount ("Tashfeen" , 1000 )
print (acc .deposit (500 )) # Deposited 500. Balance: 1500
def safe_divide (a , b ):
try :
result = a / b
except ZeroDivisionError :
print ("Error: Cannot divide by zero!" )
return None
except TypeError :
print ("Error: Invalid input type!" )
return None
else :
return result
finally :
print ("Operation complete." )
safe_divide (10 , 2 ) # 5.0
safe_divide (10 , 0 ) # Error: Cannot divide by zero!
๐ท HTTP Methods in FastAPI (Lecture 23)
from fastapi import FastAPI
from pydantic import BaseModel
app = FastAPI ()
class Item (BaseModel ):
name : str
price : float
# GET โ retrieve data
@app .get ("/items/" )
def get_items ():
return {"items" : []}
# POST โ create new resource
@app .post ("/items/" )
def create_item (item : Item ):
return {"id" : 1 , "item" : item }
# PUT โ update existing resource
@app .put ("/items/{item_id}" )
def update_item (item_id : int , item : Item ):
return {"id" : item_id , "updated" : item }
# DELETE โ remove resource
@app .delete ("/items/{item_id}" )
def delete_item (item_id : int ):
return {"message" : f"Item { item_id } deleted" }
๐ท FastAPI Routers โ Modular Design (Lecture 24)
# items_router.py โ separate file for item routes
from fastapi import APIRouter
items_router = APIRouter ()
@items_router .get ("/" )
def get_all_items ():
return {"items" : ["laptop" , "phone" , "tablet" ]}
@items_router .post ("/" )
def add_item (name : str , price : float ):
return {"message" : f"{ name } added" , "price" : price }
# main.py โ include routers in main app
from fastapi import FastAPI
from items_router import items_router
app = FastAPI ()
# Include router with prefix
app .include_router (items_router , prefix = "/items" , tags = ["Shop Items" ])
# Now /items/ โ items_router endpoints
# Docs at: http://127.0.0.1:8000/docs
๐ท Path & Query Parameters (Lecture 23)
# Path Parameter โ part of URL
@app .get ("/items/{item_id}" )
def get_item (item_id : int ):
return {"item_id" : item_id }
# Usage: GET /items/42
# Query Parameter โ optional, after ?
@app .get ("/items/" )
def get_items (skip : int = 0 , limit : int = 10 , q : str = None ):
return {"skip" : skip , "limit" : limit , "search" : q }
# Usage: GET /items/?skip=0&limit=5&q=laptop
import requests
def ask_llm (prompt : str , api_key : str ) -> str :
response = requests .post (
"https://api.groq.com/openai/v1/chat/completions" ,
headers = {"Authorization" : f"Bearer { api_key } " },
json = {
"model" : "llama3-8b-8192" ,
"messages" : [{"role" : "user" , "content" : prompt }]
}
)
return response .json ()["choices" ][0 ]["message" ]["content" ]
result = ask_llm ("Explain FastAPI in one line" , api_key = "your_key" )
print (result )
# Clone the repo
git clone https://github.com/tashfeen786/Python_Programming.git
cd Python_Programming
# Install dependencies
pip install jupyter fastapi uvicorn requests pydantic
# Launch Jupyter notebooks
jupyter notebook
# Run FastAPI server
uvicorn main:app --reload
# Docs at: http://localhost:8000/docs
๐๏ธ Project Structure
Python_Programming/
โ
โโโ ๐ Foundations
โ โโโ Lecture_04.ipynb # Python basics
โ โโโ Python_Lecture_04_part02_Data_types.ipynb # Data types
โ โโโ Python_Lecture_05_Operators.ipynb # Operators
โ โโโ Python_Lecture_06_Loops.ipynb # Loops
โ โโโ Lecture_07_Conditional_Statements.ipynb # Conditionals
โ
โโโ ๐ Functions
โ โโโ Lecture 08 โ Built-in Functions.ipynb
โ โโโ Lecture_09_User_Defined_Functions.ipynb
โ โโโ Lecture 10 โ Scope & Identity.ipynb
โ โโโ Lecture 11 โ Higher Order Functions.ipynb
โ โโโ Lecture 12 โ Decorators.ipynb
โ โโโ Lecture 22 โ Required & Optional Parameters/
โ
โโโ ๐ Error Handling & File I/O
โ โโโ Lecture-13-file_Handling_json.ipynb
โ โโโ Lecture 14 โ Exception Handling.ipynb
โ
โโโ ๐ OOP
โ โโโ Lecture 16 โ OOP Basics.ipynb
โ
โโโ โก FastAPI & Web Development
โ โโโ intro_to_fastapi_basic.ipynb # FastAPI intro
โ โโโ Lecture_23_FastAPI_Routers.pptx # HTTP Methods + Routers
โ โโโ Lecture_24-HTTP-Methods.pptx # Modular API design
โ
โโโ ๐ค AI Integration
โ โโโ intro_to_ai_apis.ipynb # LLM API calls
โ
โโโ ๐ Assignments & Practice
โ โโโ Assignment_01.ipynb
โ โโโ Assignment_02.ipynb
โ โโโ Practice_Lec_01.ipynb
โ
โโโ ๐ Notes/ # Study notes
๐ How This Connects to Real Projects
Skill Learned
Applied In
OOP & Classes
FastAPI models, Pydantic schemas
Decorators
@app.get(), @app.post() route decorators
Exception Handling
Production API error handling
File & JSON I/O
Data loading in ML pipelines
FastAPI basics
CryptoChat backend
FastAPI Routers
HelmetEye modular API structure
HTTP Methods
REST API design in all backend projects
AI API integration
LangChain ยท RAG systems
Tashfeen Aziz โ AI/ML Engineer & Python Developer
โญ If you found this helpful, please give it a star!