Free Download · No Sign-Up Required

Python
Question Set

120+ carefully curated Python interview questions covering syntax basics, OOP, data structures, file handling, decorators, generators, async programming, testing, and more — ideal for freshers and experienced developers alike.

Browse Questions ↓
120+ Total Questions
12 Topics Covered
3 Levels Difficulty
100% No Cost Ever

12 Key Python Areas

Questions span 12 core domains — from Python syntax fundamentals and OOP all the way to decorators, generators, async I/O, testing, and real-world Pythonic patterns.

All 120+ Questions

Browse all questions below — or download the beautifully formatted PDF for offline study and interview prep.

🐍
12 Qs
01What is Python? List its key features: dynamic typing, interpreted, garbage-collected, and high-level syntax.Basic
02What is the difference between Python 2 and Python 3? Name at least five breaking changes.Basic
03Explain Python's memory management and how the garbage collector works (reference counting + cyclic GC).Medium
04What is the difference between is and == in Python? When can is give unexpected results?Basic
05What are mutable vs immutable types in Python? Give three examples of each.Basic
06Explain Python's pass, break, and continue statements with examples.Basic
07What is list comprehension? Write a comprehension that squares only the even numbers from 1 to 20.Basic
08What are *args and **kwargs? Provide an example function that uses both.Basic
09What is the difference between global and nonlocal keywords? When is each needed?Medium
10What is the walrus operator (:=)? Give an example where it simplifies code.Medium
11What are f-strings? Compare them to % formatting and str.format() in terms of readability and performance.Basic
12What is the purpose of __name__ == '__main__'? Why is it a best practice in Python scripts?Basic
📦
12 Qs
13What is the difference between a list and a tuple? When would you prefer one over the other?Basic
14How does Python's dict work internally? Explain hashing and collision resolution.Medium
15What is a set in Python? Explain set operations: union, intersection, difference, and symmetric difference.Basic
16What is a frozenset? How does it differ from a set and when is it useful?Medium
17Explain Python string slicing. What does s[::-1] do? How is slicing implemented internally?Basic
18What is the collections module? Describe Counter, defaultdict, OrderedDict, and deque.Medium
19What is the difference between list.append() and list.extend()? How does list.insert() work?Basic
20What are dictionary views (.keys(), .values(), .items())? Are they static snapshots or live views?Medium
21How do you sort a list of dictionaries by a specific key? Write code using both sorted() and key=.Basic
22What is the time complexity of common operations on list, dict, and set in Python?Medium
23What is a namedtuple? How does it compare to a regular class for structured data?Medium
24Explain shallow copy vs deep copy. What is the difference between copy.copy() and copy.deepcopy()?Medium
🔁
10 Qs
25What is the LEGB rule in Python? Explain Local, Enclosing, Global, and Built-in scopes with an example.Medium
26What is a lambda function? When should you use it and when should you prefer a named function?Basic
27Explain map(), filter(), and reduce(). When are they preferable to list comprehensions?Medium
28What is a default mutable argument pitfall? Why is using def f(lst=[]) dangerous and how do you fix it?Medium
29What is function annotation in Python? How does typing module enhance type hints?Medium
30What is a first-class function in Python? How does passing functions as arguments enable higher-order functions?Medium
31What is the difference between return and yield in a function?Basic
32What is memoization? Implement it manually and then using functools.lru_cache.Medium
33What is functools.partial? Write an example showing how it creates specialised functions.Medium
34What is recursion in Python? What is the default recursion limit and how can you change it safely?Medium
🏗️
12 Qs
35What are the four pillars of OOP? Explain Encapsulation, Abstraction, Inheritance, and Polymorphism in Python context.Basic
36What is the difference between __init__ and __new__? When would you override __new__?Medium
37What are class methods, static methods, and instance methods? Explain with @classmethod and @staticmethod.Medium
38What is multiple inheritance in Python? How does the MRO (Method Resolution Order) and C3 linearisation work?Advanced
39What are dunder (magic) methods? Explain __str__, __repr__, __len__, __eq__, and __hash__.Medium
40What is a property decorator? How does it differ from using getter/setter methods directly?Medium
41What is __slots__? How does it reduce memory usage and what are its trade-offs?Advanced
42What is an abstract base class (ABC)? How do you define and enforce interfaces using abc.ABCMeta?Medium
43What is the difference between composition and inheritance? When should you prefer one over the other?Medium
44What is a mixin in Python? Provide an example of a logging mixin added to multiple classes.Advanced
45What is super()? How does it work in single and multiple inheritance scenarios?Medium
46What is a dataclass (@dataclass)? How does it compare to namedtuple and a regular class?Medium
🎭
10 Qs
47What is a closure in Python? Write an example counter factory function demonstrating closure over a mutable variable.Medium
48What is a decorator? Explain how it wraps a function using the @ syntax and functools.wraps.Medium
49Write a timing decorator that logs how long any function takes to execute.Medium
50What is a parametrised decorator? Write a decorator factory @retry(times=3) that retries a function on exception.Advanced
51How do you stack multiple decorators in Python? In what order are they applied?Medium
52What is a class-based decorator? Show how to implement __call__ to make a class behave like a decorator.Advanced
53What is functools.wraps and why must you use it when writing decorators?Medium
54What is the difference between a decorator and a context manager? When would you use each pattern?Medium
55What built-in decorators does Python provide? Explain @property, @classmethod, @staticmethod, and @abstractmethod.Basic
56What is a late-binding closure? Explain the classic loop variable capture bug and how to fix it.Advanced
⚙️
10 Qs
57What is an iterator in Python? Explain the __iter__ and __next__ protocol.Medium
58What is a generator function? How does yield work and what is the state preserved between calls?Medium
59What is a generator expression? Compare its memory usage to a list comprehension for large datasets.Medium
60What is yield from? How does it delegate to a sub-generator and simplify recursive generators?Advanced
61What is the itertools module? Describe chain, islice, product, combinations, and groupby.Medium
62How can you send values back into a generator using .send()? Write a simple coroutine example.Advanced
63What is the difference between StopIteration and GeneratorExit? When is each raised?Advanced
64Write an infinite generator that yields the Fibonacci sequence. Show how to safely consume it with islice.Medium
65What is lazy evaluation? How do Python generators enable processing of huge files line-by-line without loading into memory?Medium
66How do you make a custom class iterable? Implement __iter__ and __next__ on a Range-like class.Medium
📂
8 Qs
67How do you open, read, write, and close a file in Python? Explain different file modes: r, w, a, rb, rb+.Basic
68What is a context manager? Explain with open() and implement a custom context manager using __enter__ and __exit__.Medium
69How do you read a very large file efficiently in Python without loading it entirely into memory?Medium
70What is the pathlib module? How does it improve over os.path for file path manipulation?Medium
71How do you read and write CSV files in Python? Compare csv module vs pandas.read_csv.Basic
72How do you serialize and deserialize Python objects? Compare pickle, json, and shelve.Medium
73What is contextlib.contextmanager? Show how to create a context manager using a generator function.Medium
74How do you handle file encoding issues in Python? What is the role of the encoding and errors parameters in open()?Medium
⚠️
8 Qs
75What is the exception hierarchy in Python? Where do Exception, BaseException, and SystemExit fit?Medium
76Explain the full try / except / else / finally pattern. When is else executed vs finally?Basic
77How do you create a custom exception class? What is the best practice for adding context data to it?Medium
78What is exception chaining? Explain raise X from Y and how it preserves the original traceback.Advanced
79What is the difference between catching Exception and BaseException? Why is catching BaseException dangerous?Medium
80What is warnings.warn()? How do you suppress or promote warnings in Python?Medium
81How do you log exceptions in Python using the logging module? Explain logging.exception() vs logging.error().Medium
82What is EAFP vs LBYL? Which style does Python prefer and why?Medium
10 Qs
83What is the Global Interpreter Lock (GIL)? How does it affect multi-threaded Python programs?Advanced
84What is the difference between threading, multiprocessing, and asyncio in Python? When should you use each?Medium
85What is asyncio? Explain the event loop, coroutines, async def, and await.Medium
86What is asyncio.gather()? How does it run multiple coroutines concurrently and collect results?Medium
87What is the difference between asyncio.Task and a coroutine object? How do you create and cancel a Task?Advanced
88What is concurrent.futures? Compare ThreadPoolExecutor and ProcessPoolExecutor.Medium
89What is a race condition? How do you prevent it using threading.Lock or asyncio.Lock?Advanced
90What is queue.Queue? How is it used for thread-safe communication between producer and consumer threads?Medium
91What is asyncio.Semaphore? How would you limit concurrent HTTP requests to 10 at a time?Advanced
92What is the multiprocessing.Pool? How does pool.map() parallelise CPU-bound tasks across processes?Medium
🧪
8 Qs
93What is unittest? Write a test case with setUp, tearDown, and common assertion methods.Basic
94What is pytest? How does it differ from unittest? Explain fixtures, parametrise, and marks.Medium
95What is mocking? Show how to use unittest.mock.patch to mock an external API call in a test.Medium
96What is test coverage? How do you measure it with pytest-cov and what is a realistic target?Medium
97What is TDD (Test-Driven Development)? Describe the Red-Green-Refactor cycle with a Python example.Medium
98How do you debug Python code? Compare pdb, breakpoint(), IDE debuggers, and logging for debugging strategies.Medium
99What is property-based testing? Show an example using hypothesis to test a sorting function.Advanced
100What are doctest and inline tests? How do you run them and what scenarios are they best suited for?Basic
📚
8 Qs
101What is the difference between a module and a package in Python? What is the role of __init__.py?Basic
102How does Python's import system work? Explain sys.path, PYTHONPATH, and the import search order.Medium
103What is the difference between import X, from X import Y, and import X as Z? What are the namespace implications?Basic
104What is a virtual environment? Explain venv, pip, and requirements.txt best practices.Basic
105What is __all__ in a module? How does it control what is exported by from module import *?Medium
106What is circular import and how do you resolve it? Show a before/after refactoring example.Medium
107What are namespace packages (PEP 420)? How do they differ from regular packages with __init__.py?Advanced
108How do you package and publish a Python library to PyPI? Explain pyproject.toml, build, and twine.Advanced
🚀
12 Qs
109What are metaclasses in Python? How does type act as the default metaclass and when would you write a custom one?Advanced
110What is a descriptor protocol (__get__, __set__, __delete__)? How does property use it internally?Advanced
111What is __getattr__ vs __getattribute__? When is each called and what is the difference in behaviour?Advanced
112What are Python protocols (structural subtyping)? How does typing.Protocol differ from ABCs?Advanced
113What is the __missing__ method in a dict subclass? How is it used in collections.defaultdict?Advanced
114What are Python 3.10+ structural pattern matching (match / case) statements? Give a practical example.Medium
115What is __init_subclass__? How can it replace simple metaclass logic for enforcing subclass contracts?Advanced
116What is sys.settrace? How does the Python debugger (pdb) use it internally?Advanced
117What is monkey patching? Give a real-world scenario and explain the risks of using it in production code.Advanced
118What is the __call__ method? Write a class whose instances behave as callable functions with internal state.Medium
119What are weakref references? How do they help avoid memory leaks in observer/cache patterns?Advanced
120What is CPython vs PyPy vs Cython? When would you consider alternatives to CPython for performance-critical Python?Advanced
📥

Want all 120+ questions as a formatted PDF?

Perfect for printing, offline study, and interview prep — download completely free.

Explore Other Sets

Free question banks across all major tech domains — curated by industry experts, available to download instantly.

🤖
AI / ML Question Set
80+ Questions · Models, Algorithms, Tools
Supervised Learning Neural Networks NLP Evaluation
🗄️
SQL & Databases Question Set
85+ Questions · Queries, Joins, NoSQL
SQL Basics Joins Indexing NoSQL
🌐
Web Development Question Set
90+ Questions · HTML, CSS, JS, React
HTML/CSS JavaScript React REST APIs
📊
Data Science Question Set
80 Questions · Statistics, Pandas, Viz
Statistics Pandas NumPy EDA
🔒
Cybersecurity Question Set
60 Questions · Network, Threats, Tools
Networking Cryptography OWASP Firewalls
☁️
Cloud & DevOps Question Set
75 Questions · AWS, Docker, CI/CD
AWS Docker Kubernetes CI/CD
🐍

Get the Python PDF — Free

All 120+ questions in a beautifully formatted PDF. Delivered to your inbox instantly — no cost, no spam.

🔒 Your data is 100% safe. Unsubscribe anytime.

Join WhatsApp Channel