Expert · Python in the real world · topic 49 of 50 · 25 min
What Python is used for: web, data and AI
Explanation
One language, many jobs
You have learned core Python. Companies use that same Python with extra packages for specific work. The examples in this lesson need those packages installed with pip, so they do not run in the browser here. Read them to see how familiar they look.
Web: Django and FastAPI
A web framework is a package that handles the repeated parts of a website: reading the address the user visited, talking to the database and sending back a page or data. Django is a large "batteries included" framework. FastAPI is a lighter framework for APIs. An API (application programming interface) is a web address that returns data, usually JSON, for apps to use.
# needs: pip install fastapi uvicorn (does not run here)
from fastapi import FastAPI
app = FastAPI()
@app.get("/price/{item}")
def price(item: str):
prices = {"chai": 15, "samosa": 20}
return {"item": item, "price": prices.get(item, 0)}# a Django view (inside a Django project; does not run here)
from django.http import JsonResponse
def hello(request):
return JsonResponse({"message": "Namaste"})Data: pandas
pandas is the most used package for working with tables of data. Its main object, the DataFrame, is a table with named columns, like an Excel sheet inside Python.
# needs: pip install pandas (does not run here)
import pandas as pd
df = pd.read_csv("expenses.csv")
print(df.groupby("category")["amount"].sum())Under the hood, groupby does what you can already write with a dict and a loop:
expenses = [("food", 250), ("travel", 120), ("food", 90)]
totals = {}
for category, amount in expenses:
totals[category] = totals.get(category, 0) + amount
print(totals)AI and machine learning
Machine learning means the computer learns patterns from examples instead of following rules you write by hand. scikit-learn is used for classic models (for example predicting house prices), and PyTorch for deep learning (images, speech, language). Many apps also call large language models through an API using a few lines of Python.
model.fit(examples, answers) # learn from past data
model.predict(new_examples) # guess answers for new dataAutomation and scripting
Many people first use Python at work to automate boring jobs: renaming files, filling Excel sheets, sending reports, cleaning data. The standard library (os, pathlib, csv, json, datetime) covers much of this.
| Area | Main packages | Typical job titles |
|---|---|---|
| Web back end | Django, FastAPI, Flask | Python developer, back-end developer |
| Data | pandas, NumPy, Matplotlib | Data analyst |
| AI / ML | scikit-learn, PyTorch | ML engineer, data scientist |
| Automation and testing | standard library, pytest, Selenium | Automation engineer, QA engineer |
Watch the lesson
What Python is used for: web, data and AI · 1/6
You know core Python now. Let us see what people build with it at work.
Prefer a video by a teacher? Find free videos on “what can you do with python web data science ai” on YouTube ↗
In real life: A canteen owner's sales report
Lakshmi runs a college canteen. Every day her billing app saves sales in a CSV file. A short pandas script groups sales by item and shows the bestsellers, a FastAPI app shows today's menu prices to students on their phones, and later a simple model could predict how many samosas to make on exam days. All three are Python.
sales = [("samosa", 20), ("chai", 15), ("samosa", 20), ("vada pav", 25), ("chai", 15)]
count = {}
for item, price in sales:
count[item] = count.get(item, 0) + 1
best = max(count, key=count.get)
print("Bestseller:", best)Practice (0/3 done)
pandas groupby in plain Python: write a function total_by_category(expenses) that takes a list of dicts like {"category": "food", "amount": 250} and returns a dict of total amount per category.
A web API often filters data. Write a function students_in_city(students, city) that returns the names (in the same order) of students whose "city" matches, ignoring capital letters. Each student is a dict with "name" and "city".
Choose the area that interests you most (web, data, AI or automation) and write a one-page plan for a small project in it.
Quick quiz
Read more (free)
Pass the quiz (60% or more) or mark this topic as done when you are ready.
Your progress is saved on this device only.