πHow to Use This List
Python interviews in India usually move in three layers: core language questions, a few deeper internals questions, then live coding. This list follows the same order. Read the answer, then type the code yourself. If you are still building the basics, start with the Python roadmap.
πCore Language
1. What is the difference between mutable and immutable types?
Mutable objects can change in place: list, dict, set. Immutable objects cannot: int, float, str, tuple, frozenset. When you "change" an immutable value, Python creates a new object.2. List vs tuple?
Lists are mutable and used for collections that change. Tuples are immutable, slightly faster, hashable when their items are hashable, and used for fixed records or dictionary keys.3. How does a Python dict work?
A dict is a hash table. The key's hash decides where the value is stored, so lookups, inserts and deletes are on average O(1). Keys must be hashable. Since Python 3.7, dicts keep insertion order.4. What can be a dictionary key?
Any hashable object: str, int, float, tuple of hashables, frozenset. Lists and dicts cannot be keys because they are mutable.5. What are *args and **kwargs?
*args collects extra positional arguments into a tuple. **kwargs collects extra keyword arguments into a dict.def log(level, *args, **kwargs): print(level, args, kwargs)log("INFO", 1, 2, user="asha") # INFO (1, 2) {'user': 'asha'}6. What is the mutable default argument trap?
Default values are created once, when the function is defined.def add(item, bucket=[]): # bug: shared list bucket.append(item) return bucketdef add_fixed(item, bucket=None): if bucket is None: bucket = [] bucket.append(item) return bucket7. is vs ==?
== compares values. is compares identity, whether two names point to the same object. Use is only for None, True and False checks.8. What are list, dict and set comprehensions?
Compact ways to build collections.squares = [n * n for n in range(10) if n % 2 == 0]lengths = {w: len(w) for w in ["api", "python"]}unique = {c.lower() for c in "Python"}9. What is a lambda?
A small anonymous function with a single expression, often used as a sort key.users.sort(key=lambda u: u["age"])10. Shallow copy vs deep copy?
A shallow copy creates a new outer object but shares nested objects. A deep copy copies everything recursively.import copya = [[1, 2], [3]]b = copy.copy(a) # b[0] is a[0]c = copy.deepcopy(a) # fully independent11. What does the with statement do?
It uses a context manager to guarantee setup and cleanup, for example closing a file even if an error occurs.12. How do you swap two variables?
a, b = b, a. Python packs the right side into a tuple and unpacks it.πFunctions and Advanced Features
13. What is a decorator?
A function that takes a function and returns a new one with extra behaviour, such as logging, timing or caching.import functools, timedef timed(fn): @functools.wraps(fn) def wrapper(*args, **kwargs): start = time.perf_counter() result = fn(*args, **kwargs) print(fn.__name__, round(time.perf_counter() - start, 4)) return result return wrapper14. Why use functools.wraps?
It copies the original function's name, docstring and metadata onto the wrapper, so debugging and introspection still work.15. What is a generator?
A function that uses yield to produce values lazily, one at a time, keeping its state between calls. It saves memory on large data.def read_lines(path): with open(path) as f: for line in f: yield line.strip()16. Iterator vs iterable?
An iterable can return an iterator (it has __iter__), for example a list. An iterator produces items with __next__ and raises StopIteration when done. Generators are iterators.17. Generator expression vs list comprehension?
(x for x in data) is lazy and memory efficient. [x for x in data] builds the whole list immediately.18. How do you write your own context manager?
With a class that defines __enter__ and __exit__, or more simply with contextlib.contextmanager.from contextlib import contextmanager@contextmanagerdef opened(path): f = open(path) try: yield f finally: f.close()19. What are closures?
An inner function that remembers variables from the enclosing scope even after the outer function has returned. Decorators rely on closures.20. What does functools.lru_cache do?
It memoises a function, storing results for previous arguments so repeated calls are instant. Useful for recursive problems such as Fibonacci.πConcurrency and Internals
21. What is the GIL?
The Global Interpreter Lock in CPython allows only one thread to run Python bytecode at a time. Threads still help for I/O-bound work, but CPU-bound work needs multiple processes. Recent Python versions offer an experimental free-threaded build, but the standard build still has the GIL, so the classic answer remains the safe one in interviews.22. Threading vs multiprocessing vs asyncio?
23. Show a simple asyncio example.
import asyncioasync def fetch(n): await asyncio.sleep(1) return nasync def main(): results = await asyncio.gather(*(fetch(i) for i in range(5))) print(results)asyncio.run(main())24. How is memory managed in Python?
Mainly by reference counting, with a cyclic garbage collector to clean up reference cycles.25. What are __slots__?
A class attribute that fixes the allowed instance attributes, saving memory and preventing typos when you create many objects.πObject-Oriented Python
26. What is self?
The instance the method is called on. Python passes it automatically as the first argument.27. @staticmethod vs @classmethod?
A static method gets no automatic first argument. A class method receives the class (cls), often used for alternative constructors.28. What are dunder methods?
Special methods with double underscores, such as __init__, __str__, __repr__, __len__, __eq__ and __lt__, that let your classes work with built-in syntax.29. __str__ vs __repr__?
__str__ is the readable version for users. __repr__ is the unambiguous version for developers, ideally one you could paste back into code.30. How does inheritance and MRO work?
Python supports multiple inheritance. The Method Resolution Order (C3 linearisation) decides which parent's method runs. super() follows the MRO.31. What are dataclasses?
A decorator that generates __init__, __repr__ and __eq__ for simple data classes.from dataclasses import dataclass@dataclassclass Order: id: int amount: float paid: bool = FalseπErrors and Typing
32. try, except, else and finally?
try runs code that may fail, except handles the error, else runs only if nothing failed, finally always runs.33. How do you create a custom exception?
Subclass Exception and raise it with a clear message.class InsufficientBalance(Exception): passraise InsufficientBalance("Balance too low for this withdrawal")34. What are type hints and are they enforced?
They document expected types, such as def total(items: list[float]) -> float. Python does not enforce them at runtime; tools such as mypy and editors check them.πCommon Coding Questions
35. Reverse a string
s[::-1]36. Check if a string is a palindrome
def is_palindrome(s): cleaned = "".join(c.lower() for c in s if c.isalnum()) return cleaned == cleaned[::-1]37. Count word frequency
from collections import CounterCounter("the cat and the hat".split()).most_common(2)38. Find duplicates in a list
def duplicates(items): seen, dups = set(), set() for x in items: if x in seen: dups.add(x) seen.add(x) return dups39. Two Sum
def two_sum(nums, target): index = {} for i, n in enumerate(nums): if target - n in index: return [index[target - n], i] index[n] = i40. Flatten a nested list
def flatten(items): for x in items: if isinstance(x, list): yield from flatten(x) else: yield xPractise more problems like these in our free DSA practice, which runs Python in your browser.
πFAQ
What Python topics are asked most for freshers?
Data types, mutability, lists vs tuples, dicts, functions, *args and **kwargs, OOP basics, exceptions and simple coding problems on strings and lists.Do Python interviews ask about the GIL and asyncio?
For experienced roles, yes, especially backend and data engineering. Freshers should know the basic answer to questions 21 and 22.Which Python version should I prepare with?
Use a current Python 3 release. Interviewers expect modern features such as f-strings, type hints and dataclasses.How should I practise coding questions?
Solve a few problems daily, explain your approach aloud, and state the time complexity. Mock interviews help more than reading answers.πLearn It Live
Prakalpana's Python Programming course is taught live online with an optional 1-on-1 track, real projects and mock interviews built around questions like these. See the Python track, then WhatsApp or call +91 9180377502 for a free demo.