Python

Rishabh SinghRishabh Singh
3 min read

1️⃣ Core Python Concepts I Use Daily

📦 Data Types (These map directly to JSON data!)

  • List → Think of it as an array of values coming from an API: [1, 'Flask', True]

  • Tuple → Unchangeable config values like ('DEBUG', False)

  • Set → For filtering out duplicate user IDs

  • Dict → Backend gold: Every JSON object becomes a dictionary in Python{ "user": "rishabh", "age": 23}

🧠 Control Flow

  • if/else → Classic auth checks

  • for/while → Iterating over DB rows or JSON keys

🔁 Comprehensions & Generators

  • One-liners for filtering lists or serializing DB records.

  • Generator = lightweight API paginators, async-ready!

🧯 Exception Handling

  • Use try/except while handling requests, DB connections, or auth logic. It’s cleaner and more Pythonic than checking every condition.

2️⃣ OOP in Real Backend Apps

Let me break it down how I understood it:

ConceptHow I Actually Use It
ClassBlueprint for models (like Task, User)
ObjectActual DB row, or user session
ConstructorSet up initial data like __init__(self) in Flask views
InheritanceExtend base classes in Flask/JWT/Auth
EncapsulationKeep internal logic hidden (e.g., password hashing)
PolymorphismThink of different serializers/validators responding to same method call

Also, __str__ is super useful when debugging models in logs.


3️⃣ Writing Pythonic Code

Python is beautiful when written right.

  • enumerate() → Index + value in loops (great for CLI apps)

  • zip() → Combine two lists, useful in data processing

  • any() / all() → Quick validation checks

  • Use comprehensions instead of for loops where possible.

  • Follow EAFP (Easier to Ask Forgiveness than Permission) instead of checking every if.


4️⃣ File Handling & Data Interchange

You’ll often deal with:

  • Config files (.env, .json)

  • User data (JSON from frontend)

  • Exporting reports (CSV or PDF)

My go-to approach:

pythonCopyEditwith open('config.json') as f:
    config = json.load(f)

Safe, clean, and closes the file automatically.


5️⃣ Decorators & Closures

I use decorators in:

  • Flask for @app.route and @jwt_required

  • Custom middlewares for logging, permissions, API key validation

Closures are handy when I want to retain some data inside a nested function (used once to build a rate limiter without external libs).


6️⃣ Iterators, Generators, and Async

When building data-heavy features or working with async frameworks like FastAPI:

  • Generator: Stream DB rows without loading all at once

  • Iterator: Custom __iter__ objects for pagination

  • Asyncio: Used for background jobs, emailing, etc.

For API calls, I often use httpx (async) or requests (sync).


7️⃣ Concurrency Basics for Backend

  • threading → Great for logging or sending emails in background

  • multiprocessing → Batch jobs and heavy calculations

  • asyncio → My favorite when building event-driven APIs in FastAPI


8️⃣ Data Structures & Algorithms (Still important!)

Even though frameworks handle a lot, knowing Big O helped me write faster code and optimize DB queries.

I practiced:

  • Searching/sorting logic with lists and dicts

  • Use collections.Counter, deque, defaultdict when needed

0
Subscribe to my newsletter

Read articles from Rishabh Singh directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

Rishabh Singh
Rishabh Singh

📚 Avid reader | ⚡ Percy Jackson fan 👨‍💻 Learning backend development | Currently working with Python 🤝 Here to share, help, and grow with the dev community 🛤️ Follow my journey as I learn, build, and explore the backend world!