Python is the most versatile language in the Indian tech interview landscape: used for backend web development, data science, machine learning, scripting, and DevOps automation. Whether you are applying for a backend SDE role at Swiggy, a data science position at Flipkart, or an ML role at a funded startup, Python fluency is expected. This guide covers the Python concepts most commonly tested across different role types at Indian companies.
Python fundamentals tested at all interview levels
Q: What is the difference between a list and a tuple? List: mutable (elements can be changed), defined with []. Tuple: immutable (elements cannot be changed), defined with (). Tuples are faster and use less memory. Use tuples for fixed collections (coordinates, RGB values, database rows). Lists for collections that change. Tuples can be used as dictionary keys; lists cannot.
Q: What is a dictionary and how does it work internally? A dictionary (dict) is a hash map: key-value pairs with O(1) average-case lookup. Python dicts are ordered by insertion order since Python 3.7. Internal implementation uses open addressing with a compact hash table. Collision resolution uses probing. dict.get(key, default) is safer than dict[key] which raises KeyError on missing keys.
Q: What are list comprehensions, and when should you use them? `[x*2 for x in range(10) if x % 2 == 0]`: concise, readable, and faster than equivalent for loops. Use when creating a new list from an iterable with optional filtering. Do NOT use for complex multi-step transformations or when the logic is hard to read in one line: readability matters more.
Q: What is the difference between `is` and `==`? `==` compares values (are the objects equal?). `is` compares identity (are they the same object in memory?). `is` is only correct for checking None (`if x is None:`): never use `is` to compare strings or integers in production code.
Q: What are args and kwargs? `args` collects extra positional arguments into a tuple. `**kwargs` collects extra keyword arguments into a dict. Used in function signatures to accept variable-length arguments. Common in decorator patterns and framework APIs.
Python OOP, decorators, and functional concepts
Q: How does Python's class system work? Python uses new-style classes (all classes inherit from object). `_init` is the constructor. `self` is the first parameter of all instance methods (explicit in Python, implicit in Java). `str` for human-readable string, `repr_` for developer/debug string. Python supports multiple inheritance: MRO (Method Resolution Order) follows C3 linearisation.
Q: What is a decorator? A decorator is a function that takes a function and returns a modified function: a clean way to add behaviour (logging, timing, authentication checks) without modifying the original function. `@property` converts a method to a read-only attribute. `@classmethod` passes the class instead of the instance. `@staticmethod` is a function that happens to live in the class.
Q: What is a generator and how does it differ from a list? A generator produces values lazily: one at a time, on demand: using `yield`. It does not store all values in memory. A list stores all values immediately. `sum(xx for x in range(10*9))` works fine with a generator but would crash with a list. Use generators for large or infinite sequences.
Q: What is the GIL (Global Interpreter Lock)? The GIL is a mutex in CPython that allows only one thread to execute Python bytecode at a time. This means CPU-bound code does not benefit from multithreading in Python. Solutions: use multiprocessing (multiple processes bypass the GIL) for CPU-bound tasks, asyncio for I/O-bound tasks, or C extensions (NumPy, SciPy) which release the GIL.
Python for web and data roles
Backend web with Django/FastAPI (asked at Swiggy, Razorpay, Indian startups):
Django: ORM (models map to database tables), migrations, admin panel, MVT pattern. `QuerySet` is lazy: queries run only when evaluated. Select related / prefetch related to avoid N+1. Django REST Framework for building APIs.
FastAPI: Modern, async-first. Python type annotations generate OpenAPI docs automatically. `async def` route handlers handle concurrent requests without blocking. Background tasks for fire-and-forget operations.
Common interview question: 'How does Django handle a database query?' ORM → generates SQL → sends to database → maps result rows to model instances. QuerySets are lazy: `User.objects.filter(...)` does not execute until you iterate, call len(), or convert to list.
Python for data science (asked at Flipkart, Meesho, Amazon India data roles):
- pandas: DataFrame operations, groupby, merge (similar to SQL joins), pivot tables, handling missing values.
- numpy: Vectorised operations on arrays: faster than Python loops. Broadcasting rules.
- Common interview: 'Write a pandas operation to find the top 3 categories by revenue.' `df.groupby('category')['revenue'].sum().nlargest(3)`
Frequently asked questions
Practice these questions on HireStepX