Skip to content

Python Use Cases

Python’s versatility makes it suitable for almost every domain in software development.

from sklearn.linear_model import LinearRegression
import numpy as np
# House price prediction
X = np.array([[500], [750], [1000], [1500], [2000]])
y = np.array([150000, 200000, 250000, 350000, 450000])
model = LinearRegression()
model.fit(X, y)
print(model.predict([[1200]])) # ~290,000

Libraries: TensorFlow, PyTorch, scikit-learn, Keras, Hugging Face

Companies: Google, OpenAI, Tesla, Netflix

from flask import Flask, jsonify
app = Flask(__name__)
@app.route('/api/users', methods=['GET'])
def get_users():
users = [{"id": 1, "name": "Alice"}, {"id": 2, "name": "Bob"}]
return jsonify(users)

Frameworks: Django, Flask, FastAPI, Tornado

Companies: Instagram (Django), Pinterest, Spotify (Flask)

import os
import re
for filename in os.listdir("/downloads/reports"):
match = re.match(r"report_(\d{4})_(\d{2})\.pdf", filename)
if match:
year, month = match.groups()
new_name = f"{year}-{month}-report.pdf"
os.rename(
os.path.join(folder, filename),
os.path.join(folder, new_name)
)

Libraries: Selenium, PyAutoGUI, Playwright

import pandas as pd
import matplotlib.pyplot as plt
df = pd.read_csv("sales_2024.csv")
top_products = df.groupby("product")["revenue"].sum().sort_values(ascending=False).head(5)
top_products.plot(kind="bar", title="Top 5 Products by Revenue")
plt.savefig("top_products.png")

Libraries: Pandas, NumPy, Matplotlib, Seaborn, Plotly, Jupyter

import socket
def scan_port(host, port):
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s:
s.settimeout(0.5)
result = s.connect_ex((host, port))
return port, "OPEN" if result == 0 else "CLOSED"

Libraries: Scapy, Paramiko, Cryptography, Scapy

import boto3
ec2 = boto3.client('ec2', region_name='us-east-1')
response = ec2.describe_instances(
Filters=[{'Name': 'instance-state-name', 'Values': ['running']}]
)

Tools: Ansible, boto3, Fabric, Docker SDK

Python’s diverse applications make it a valuable skill across many career paths.

Q1: What are the main domains where Python is used?

A: Python is used in AI/ML, web development, data science, automation, cybersecurity, DevOps, finance, and IoT/embedded systems.

Q2: What makes Python suitable for AI/ML?

A: Extensive libraries (TensorFlow, PyTorch, scikit-learn), readability (data scientists can focus on algorithms), and integration with C/C++ for performance.

  1. Research and list 3 companies using Python in production.
  2. Write a simple automation script for a repetitive task you do.
  3. Build a basic web API with Flask or FastAPI.