Python is the dominant language for data engineering, ML engineering, and backend development at Indian product companies and startups. Whether you are applying as a Python backend engineer (Django, FastAPI), a data scientist, or an ML engineer, the interview covers overlapping but distinct territory. This guide covers the core Python concepts (OOP, generators, decorators, GIL, async), the Django and Flask questions asked at most Indian companies, and the coding questions interviewers actually use.
Core Python Concepts Tested in Indian Interviews
Six core areas: (1) OOP: classes, inheritance, MRO (C3 linearisation for multiple inheritance), dunder methods (_init, str, repr, len, eq, enter, exit). (2) Generators and iterators: generators use yield; produce values lazily on demand instead of materialising all values in memory. Generator expressions vs list comprehensions: (x*2 for x in range(1000)) is memory-efficient; [x*2 for x in range(1000)] allocates immediately. (3) Decorators: a function that wraps another function, returning a new function with the same signature (use functools.wraps to preserve metadata). Common patterns: logging, authentication, rate limiting, caching. (4) Context managers: the with statement; implement via enter/exit_ or @contextlib.contextmanager. Guarantees cleanup even on exceptions. (5) GIL: CPython's Global Interpreter Lock prevents true parallel CPU execution on multiple threads. For CPU-bound work use multiprocessing; for I/O-bound work use threading or asyncio. (6) Python memory model: mutable vs immutable (lists are mutable: modifying them in a function affects the caller's reference; integers and strings are immutable).
Django and Flask Questions in Indian Python Interviews
Django ORM: selectrelated performs a SQL JOIN for ForeignKey/OneToOne, fetching the related object in one query. prefetchrelated performs a separate query for ManyToMany or reverse FK and does Python-level joining, better when the related set is large or has many-to-many. N+1 problem: accessing a related object inside a loop without select_related causes one query per iteration.
Django REST Framework: serializers (model-to-JSON conversion with validation), ViewSets (combines list, retrieve, create, update, destroy into one class), authentication (SessionAuthentication, TokenAuthentication, JWTAuthentication), permissions (IsAuthenticated, IsAdminUser, custom permission classes).
Flask vs Django decision: Flask is a microframework with no ORM, admin, or auth out of the box; choose it when you want full control over the stack or building a small API. Django provides these batteries included; choose it for applications that need admin, auth, and a full ORM without assembling them manually.
FastAPI questions (increasingly common at Indian startups): Pydantic for request/response validation, async endpoints with async def, dependency injection for database sessions and auth, OpenAPI schema auto-generation.
Python Coding Questions in Indian Tech Interviews
Common Python coding questions with solutions: (1) LRU Cache: use collections.OrderedDict with accessOrder semantics (movetoend on get, popitem(last=False) to evict oldest). (2) Flatten nested list: recursive generator using 'yield from' for each nested element, or itertools.chain with isinstance checks. (3) Find k most frequent elements: Counter from collections; then heapq.nlargest(k, counter.items(), key=lambda x: x[1]) or bucket sort. (4) Reverse a linked list: iterate with prev=None, curr=head, nxt=None; at each step: nxt=curr.next, curr.next=prev, prev=curr, curr=nxt. (5) Group anagrams: iterate strings; for each string, sort its characters as the key in a defaultdict(list), append the string. Return the values.
Python-specific gotchas interviewers test: mutable default arguments (def f(x, lst=[]) is a bug: lst persists across calls; use lst=None then lst = [] inside), late binding in closures (lambda x=i: x is the fix for the classic closure-in-loop bug), is vs == (is compares identity, not equality; integer cache makes small integers (−128 to 256) share identity in CPython but this is an implementation detail).
Practise Python developer interviews with HireStepX's AI voice interviewer. Get scored feedback on technical depth, communication clarity, and problem-solving approach. First 2 sessions free.
Practice freePython Interview Preparation by Seniority Level
Junior Python roles (0-2 years): Core syntax, OOP, list comprehensions, basic Django CRUD views, REST API consumption with requests library, SQL via ORM, pytest basics.
Mid-level Python roles (2-5 years): Decorators and context managers, generator patterns, Django ORM optimisation (selectrelated, prefetchrelated, annotate, aggregate), DRF with JWT auth, Celery for background tasks, Redis for caching, async Python with asyncio or FastAPI, pytest fixtures and parameterised tests.
Senior Python roles (5+ years): Python internals (CPython vs PyPy, GIL implications, memory management), performance profiling (cProfile, memory_profiler, py-spy), concurrency (asyncio event loop internals, ProcessPoolExecutor for CPU-bound), system design (distributed task queues, idempotent Celery tasks, database connection pooling), architecture decisions (when to choose microservices vs monolith), mentoring signals.
Frequently asked questions
Explore more