Python is the language of choice for data engineering, machine learning, and increasingly for backend microservices in Indian tech companies. It is tested at companies across the spectrum: from IT services (where Python scripting and automation skills matter) to FAANG India (where Python is accepted for coding rounds). This guide covers the complete Python developer interview question bank for India 2026.
Core Python questions and answers
Core Python interview topics:
1. Data types: - List vs tuple: list is mutable, ordered; tuple is immutable, ordered; tuples are faster to iterate and use less memory; use tuples for fixed data like coordinates or return values; use lists when the collection needs to change. - Dict internals: hash map; key is hashed, used as bucket index; O(1) average get/set/delete; Python 3.7+ preserves insertion order. - Set: unordered collection of unique hashable elements; O(1) average add/discard/contains; uses the same hashing mechanism as dict; use for membership testing and deduplication.
2. Mutability gotcha: mutable default arguments: def additem(item, lst=[]) is a classic Python bug: the default list is created once and shared across all calls. Fix: def additem(item, lst=None): if lst is None: lst = []. Always use None as the default for mutable arguments.
3. Closures and decorators: A closure is a function that captures variables from its enclosing scope. A decorator is a function that takes a function as input and returns a modified function. Use functools.wraps to preserve the original function's _name and doc_. Example: a @timer decorator that measures execution time without modifying the function body.
4. Generators: Yield instead of return; lazy evaluation: the value is computed only when requested (via next() or for loop). Use generators for large data sequences that do not fit in memory (reading a large CSV line by line). Generator expressions: (x2 for x in range(1000000)) vs list comprehension [x2 for x in range(1000000)]: the generator uses O(1) memory vs O(n).
5. Context managers: The with statement ensures _enter and exit are called; exit runs even if an exception is raised. Use for: file handles (with open()), database connections, lock acquisition, temporary directory creation. Implement with contextlib.contextmanager (generator-based) or a class with enter/exit_.
Advanced Python questions
Advanced Python concepts:
1. 'What is the GIL (Global Interpreter Lock) and when does it matter?' GIL: a mutex that allows only one thread to execute Python bytecode at a time, even on multi-core hardware. Python threads cannot parallelise CPU-bound work. Workarounds: multiprocessing (multiple processes, each with its own GIL), C extensions (numpy, pandas, and most scientific Python libraries release the GIL for heavy computations). GIL does NOT affect I/O-bound tasks: when a thread waits for network or disk I/O, it releases the GIL, allowing other threads to run. This is why Python web servers (Django, FastAPI, Gunicorn) can handle concurrent requests effectively with threading.
2. 'What is the difference between async/await and threading?' Threading: OS threads, each with its own stack; the OS schedules them; limited by the GIL for CPU-bound work. Async/await: single-threaded event loop; coroutines (async def functions) cooperatively yield control (via await) when waiting for I/O; no OS thread switching overhead; more efficient for high-concurrency I/O-bound workloads (web servers handling thousands of simultaneous connections).
3. 'How does Python manage memory?' Reference counting: each object has a reference count; when count reaches 0, the object is immediately deallocated. Garbage collector: handles cyclic references (object A references B, B references A; neither's count reaches 0 without the GC's cycle detector). Use weakref for object caches to avoid preventing garbage collection.
4. 'What is Python's MRO (Method Resolution Order)?' MRO defines the order in which Python searches base classes for a method in multiple inheritance. Python uses C3 linearisation. Check with ClassName._mro_ or ClassName.mro(). In practice: ensure your class hierarchy is designed so that MRO ambiguities do not arise; use super() correctly to call the next class in the MRO.
Django and FastAPI questions
Django interview questions:
1. 'How does the Django ORM work and how do you avoid N+1 queries?' Django ORM maps Python model classes to database tables. Model.objects.filter(field=value) generates a SQL SELECT. N+1 problem: for order in orders: print(order.user.name) without selectrelated makes 1 query for orders + N queries for each user. Fix: use selectrelated() (JOIN for foreign keys) or prefetch_related() (separate query + Python-side join for many-to-many and reverse FK).
2. 'What is Django middleware and how does it work?' Middleware: a series of hooks that process requests before they reach the view and responses before they are returned to the client. Common built-in middleware: SecurityMiddleware (HTTPS redirect, HSTS), SessionMiddleware (session handling), AuthenticationMiddleware (attaches request.user), CsrfViewMiddleware (CSRF protection). Custom middleware: a class with _init(self, getresponse) and _call_(self, request) methods.
FastAPI interview questions:
1. 'What is Pydantic and why is it used with FastAPI?' Pydantic: data validation and settings management library. Define a class inheriting from BaseModel; Pydantic validates that input data matches the declared types at runtime and produces clear error messages on validation failure. FastAPI uses Pydantic models for request body validation and response serialisation, plus automatic OpenAPI/Swagger documentation from the same model definition.
2. 'How does FastAPI handle asynchronous requests?' FastAPI is built on Starlette (an ASGI framework) and supports async def route handlers natively. An async route handler can await I/O operations (database queries, HTTP calls) without blocking the event loop, allowing other requests to be served concurrently by the same single-threaded process. Use async def for routes that perform I/O; use def for CPU-bound routes (FastAPI runs them in a thread pool automatically).
Practise Python interview questions with HireStepX's AI voice interviewer. Get scored feedback on OOP explanations, Django/FastAPI architecture answers, and coding walkthroughs. First 2 sessions free.
Practice freePython data structures and algorithms
Python-specific data structure questions:
1. 'How do you implement a stack and a queue in Python?' Stack (LIFO): use a list with .append() (push) and .pop() (pop); both O(1). Or collections.deque for thread-safe access. Queue (FIFO): use collections.deque with .append() (enqueue right) and .popleft() (dequeue left); both O(1). Do not use list for a queue: list.pop(0) is O(n).
2. 'How do you sort a list of objects in Python?' Custom key: sorted(objects, key=lambda x: x.attribute) or sorted(objects, key=attrgetter('attribute')). Multiple keys: sorted(objects, key=lambda x: (x.department, -x.salary)) (sort by department ascending, then salary descending). In-place: objects.sort(key=...) vs new list: sorted(objects, key=...).
3. 'What is the time complexity of common Python operations?' List: append O(1) amortised, pop (from end) O(1), pop (from index) O(n), insert (at index) O(n), index O(n). Dict: get/set/delete O(1) average. Set: add/discard/in O(1) average. String: concatenation (+) is O(n): use ''.join(listofstrings) for multiple concatenations (O(n) total). Sorting: O(n log n) (TimSort).
4. 'What are Python's built-in data analysis libraries and what are they used for?' numpy: numerical computing; n-dimensional arrays with vectorised operations; backbone of the Python scientific stack. pandas: tabular data analysis; DataFrame (2D labeled data); operations: filtering, groupby, merge, pivot, string operations, date handling; reads and writes CSV, Excel, JSON, SQL. matplotlib: data visualisation; plots, charts, histograms. scikit-learn: machine learning; preprocessing, model training, evaluation, cross-validation.
Python developer salary and career path in India
Python developer career in India (2024-25):
Junior Python Developer (0-2 years): 6-14 LPA Skills: Python fundamentals, Django or FastAPI, SQL, Git, REST APIs Companies: startups, IT services Python teams, data-focused product companies
Mid-level Python Developer (2-5 years): 14-30 LPA Skills: async Python, Celery for background tasks, Redis, PostgreSQL, Docker, testing (pytest), system design basics Companies: Swiggy, Razorpay, Zoho, Freshworks, mid-tier product companies
Senior Python Developer / Data Engineer (5-8 years): 30-55 LPA Skills: distributed data pipelines (Apache Spark with PySpark, Airflow, dbt), cloud-native Python (AWS Lambda, GCP Cloud Functions), performance profiling, mentoring Companies: Flipkart data platform, Swiggy data engineering, FAANG India data teams
Python for data vs backend: Python is used heavily for data engineering and ML at most Indian product companies. Backend Python (Django/FastAPI REST services) is common at startups and mid-tier companies but less common than Java at very large-scale Indian tech companies (where Java and Go dominate backend microservices).
Frequently asked questions
Explore more