Top 150+ Most Asked Python Interview Questions
Deep-dive into Python internals, memory management, and advanced features. This list avoids generic DSA and focuses on language-specific mechanics.
0%
Overall Progress
0/170
Status
Problem
Level
2.Explain Python's memory management and reference counting.Hard
2.Explain Python's memory management and reference counting.
Hard
3.What is the difference between is and ==? Give examples with strings and integers.Easy
3.What is the difference between is and ==? Give examples with strings and integers.
Easy
4.Why are small integers cached in Python? What is integer interning?Medium
4.Why are small integers cached in Python? What is integer interning?
Medium
5.What is string interning in Python?Hard
5.What is string interning in Python?
Hard
6.Explain Python's garbage collection mechanism (generational garbage collection).Hard
6.Explain Python's garbage collection mechanism (generational garbage collection).
Hard
7.What are the differences between mutable and immutable types? Why does it matter?Easy
7.What are the differences between mutable and immutable types? Why does it matter?
Easy
8.What is the id() function and what does it return?Easy
8.What is the id() function and what does it return?
Easy
9.Explain the concept of 'everything is an object' in Python.Medium
9.Explain the concept of 'everything is an object' in Python.
Medium
10.What is the difference between del and remove()?Easy
10.What is the difference between del and remove()?
Easy
11.How does Python's pass by object reference work?Hard
11.How does Python's pass by object reference work?
Hard
12.What is the difference between copy() and deepcopy()?Medium
12.What is the difference between copy() and deepcopy()?
Medium
13.Explain the sys.intern() function.Hard
13.Explain the sys.intern() function.
Hard
14.What happens when you modify a tuple containing a list?Medium
14.What happens when you modify a tuple containing a list?
Medium
15.Why can't you use a list as a dictionary key but can use a tuple?Medium
15.Why can't you use a list as a dictionary key but can use a tuple?
Medium
16.What is __pycache__ folder? What are .pyc files?Easy
16.What is __pycache__ folder? What are .pyc files?
Easy
17.What is the difference between .py and .pyc files?Easy
17.What is the difference between .py and .pyc files?
Easy
18.How does Python's bytecode compilation work?Hard
18.How does Python's bytecode compilation work?
Hard
19.What is the Python interpreter? How does it execute code?Medium
19.What is the Python interpreter? How does it execute code?
Medium
20.Explain the difference between CPython, PyPy, Jython, and IronPython.Medium
20.Explain the difference between CPython, PyPy, Jython, and IronPython.
Medium
21.What are descriptors in Python? Explain with examples.Expert
21.What are descriptors in Python? Explain with examples.
Expert
22.What is the difference between __getattr__, __getattribute__, and __get__?Expert
22.What is the difference between __getattr__, __getattribute__, and __get__?
Expert
23.Explain __setattr__, __delattr__, and __delitem__.Hard
23.Explain __setattr__, __delattr__, and __delitem__.
Hard
24.What are slots (__slots__)? When and why to use them?Hard
24.What are slots (__slots__)? When and why to use them?
Hard
25.How do __slots__ improve memory usage and performance?Expert
25.How do __slots__ improve memory usage and performance?
Expert
26.What is the difference between __new__ and __init__?Hard
26.What is the difference between __new__ and __init__?
Hard
27.When would you override __new__ instead of __init__?Expert
27.When would you override __new__ instead of __init__?
Expert
28.What are metaclasses? Give practical use cases.Expert
28.What are metaclasses? Give practical use cases.
Expert
29.How do you create a singleton using metaclasses?Expert
29.How do you create a singleton using metaclasses?
Expert
30.What is type() as a metaclass?Expert
30.What is type() as a metaclass?
Expert
31.Explain the __call__ method and callable objects.Medium
31.Explain the __call__ method and callable objects.
Medium
32.What is the difference between __str__ and __repr__?Easy
32.What is the difference between __str__ and __repr__?
Easy
33.When does Python call __repr__ vs __str__?Medium
33.When does Python call __repr__ vs __str__?
Medium
34.What are magic methods (dunder methods)? List 15 important ones.Medium
34.What are magic methods (dunder methods)? List 15 important ones.
Medium
35.Explain __enter__ and __exit__ methods.Medium
35.Explain __enter__ and __exit__ methods.
Medium
36.What is the @property decorator? How is it different from getters/setters?Easy
36.What is the @property decorator? How is it different from getters/setters?
Easy
37.How do you create read-only properties?Easy
37.How do you create read-only properties?
Easy
38.What is property deletion using @property.deleter?Medium
38.What is property deletion using @property.deleter?
Medium
39.Explain method resolution order (MRO) with multiple inheritance.Hard
39.Explain method resolution order (MRO) with multiple inheritance.
Hard
40.What is the C3 linearization algorithm?Expert
40.What is the C3 linearization algorithm?
Expert
41.What is a closure? How does it capture variables?Hard
41.What is a closure? How does it capture variables?
Hard
42.Explain the LEGB rule in Python scope.Easy
42.Explain the LEGB rule in Python scope.
Easy
43.What are the differences between local, global, and nonlocal keywords?Medium
43.What are the differences between local, global, and nonlocal keywords?
Medium
44.How do decorators work internally?Medium
44.How do decorators work internally?
Medium
45.How do you create a decorator that accepts arguments?Hard
45.How do you create a decorator that accepts arguments?
Hard
46.What is functools.wraps? Why use it in decorators?Medium
46.What is functools.wraps? Why use it in decorators?
Medium
47.How do you stack multiple decorators?Medium
47.How do you stack multiple decorators?
Medium
48.What is the difference between @staticmethod and @classmethod?Easy
48.What is the difference between @staticmethod and @classmethod?
Easy
49.When would you use @classmethod instead of __init__?Medium
49.When would you use @classmethod instead of __init__?
Medium
50.How do you create class decorators?Hard
50.How do you create class decorators?
Hard
51.What is the difference between function decorators and class decorators?Medium
51.What is the difference between function decorators and class decorators?
Medium
52.Explain functools.lru_cache decorator.Medium
52.Explain functools.lru_cache decorator.
Medium
53.What is functools.partial? Give use cases.Hard
53.What is functools.partial? Give use cases.
Hard
54.How do you create a decorator that works with and without arguments?Expert
54.How do you create a decorator that works with and without arguments?
Expert
55.What are context manager decorators (@contextmanager)?Medium
55.What are context manager decorators (@contextmanager)?
Medium
56.What is the difference between generator and iterator?Easy
56.What is the difference between generator and iterator?
Easy
57.How does the yield keyword work?Medium
57.How does the yield keyword work?
Medium
58.What is yield from? When to use it?Hard
58.What is yield from? When to use it?
Hard
59.Explain generator expressions vs list comprehensions for memory.Easy
59.Explain generator expressions vs list comprehensions for memory.
Easy
60.What happens when you call next() on an exhausted generator?Easy
60.What happens when you call next() on an exhausted generator?
Easy
61.How do you send values to a generator using send()?Hard
61.How do you send values to a generator using send()?
Hard
62.What is the throw() method in generators?Hard
62.What is the throw() method in generators?
Hard
63.What is the close() method in generators?Hard
63.What is the close() method in generators?
Hard
64.How do you create an infinite generator?Easy
64.How do you create an infinite generator?
Easy
65.What are coroutines? How are they related to generators?Hard
65.What are coroutines? How are they related to generators?
Hard
66.Explain the iterator protocol (__iter__ and __next__).Medium
66.Explain the iterator protocol (__iter__ and __next__).
Medium
67.How do you make a class iterable?Medium
67.How do you make a class iterable?
Medium
68.What is itertools module? Explain 5 useful functions.Easy
68.What is itertools module? Explain 5 useful functions.
Easy
69.What is the difference between iter() with one vs two arguments?Hard
69.What is the difference between iter() with one vs two arguments?
Hard
70.How do you chain iterators?Easy
70.How do you chain iterators?
Easy
71.What is a context manager?Easy
71.What is a context manager?
Easy
72.How does the with statement work?Medium
72.How does the with statement work?
Medium
73.How do you create a custom context manager using class?Medium
73.How do you create a custom context manager using class?
Medium
74.How do you create a context manager using @contextmanager?Medium
74.How do you create a context manager using @contextmanager?
Medium
75.What is contextlib.ExitStack?Hard
75.What is contextlib.ExitStack?
Hard
76.Can context managers suppress exceptions? How?Hard
76.Can context managers suppress exceptions? How?
Hard
77.What happens if an exception occurs in __enter__?Hard
77.What happens if an exception occurs in __enter__?
Hard
78.What are the return values of __exit__ method?Hard
78.What are the return values of __exit__ method?
Hard
79.How do you nest multiple context managers?Easy
79.How do you nest multiple context managers?
Easy
80.What is contextlib.closing?Medium
80.What is contextlib.closing?
Medium
81.What is the difference between except Exception and bare except?Medium
81.What is the difference between except Exception and bare except?
Medium
82.Why should you avoid bare except clauses?Medium
82.Why should you avoid bare except clauses?
Medium
83.What is exception chaining? Explain raise...from.Hard
83.What is exception chaining? Explain raise...from.
Hard
84.What is the difference between raise and raise Exception?Medium
84.What is the difference between raise and raise Exception?
Medium
85.How do you re-raise an exception?Easy
85.How do you re-raise an exception?
Easy
86.What is sys.exc_info()?Hard
86.What is sys.exc_info()?
Hard
87.What are exception groups (Python 3.11)?Expert
87.What are exception groups (Python 3.11)?
Expert
88.How do you create custom exception classes?Easy
88.How do you create custom exception classes?
Easy
89.What is the finally clause? When does it execute?Easy
89.What is the finally clause? When does it execute?
Easy
90.What is the else clause in try-except? When does it run?Medium
90.What is the else clause in try-except? When does it run?
Medium
91.What is the difference between a module and a package?Easy
91.What is the difference between a module and a package?
Easy
92.What is __init__.py file? Is it still needed in Python 3.3+?Medium
92.What is __init__.py file? Is it still needed in Python 3.3+?
Medium
93.What are namespace packages?Hard
93.What are namespace packages?
Hard
94.What is the difference between absolute and relative imports?Medium
94.What is the difference between absolute and relative imports?
Medium
95.How does Python's import system work?Hard
95.How does Python's import system work?
Hard
96.What is sys.path? How can you modify it?Medium
96.What is sys.path? How can you modify it?
Medium
97.What is importlib? How do you import dynamically?Hard
97.What is importlib? How do you import dynamically?
Hard
98.What is the difference between import module and from module import *?Easy
98.What is the difference between import module and from module import *?
Easy
99.What does if __name__ == '__main__' do?Easy
99.What does if __name__ == '__main__' do?
Easy
100.How do you reload a module? Why is reload() dangerous?Hard
100.How do you reload a module? Why is reload() dangerous?
Hard
101.What are circular imports? How do you avoid them?Hard
101.What are circular imports? How do you avoid them?
Hard
102.What is __all__ variable in modules?Medium
102.What is __all__ variable in modules?
Medium
103.How do you create a package with subpackages?Easy
103.How do you create a package with subpackages?
Easy
104.What is the difference between site-packages and dist-packages?Hard
104.What is the difference between site-packages and dist-packages?
Hard
105.How does virtual environment isolation work?Medium
105.How does virtual environment isolation work?
Medium
106.What is the GIL (Global Interpreter Lock)? Why does it exist?Hard
106.What is the GIL (Global Interpreter Lock)? Why does it exist?
Hard
107.How does GIL affect multithreading?Hard
107.How does GIL affect multithreading?
Hard
108.When does GIL release? (I/O operations, time)Expert
108.When does GIL release? (I/O operations, time)
Expert
109.What is the difference between threading and multiprocessing?Medium
109.What is the difference between threading and multiprocessing?
Medium
110.When would you use threading vs multiprocessing?Medium
110.When would you use threading vs multiprocessing?
Medium
111.What are daemon threads? How do they differ from non-daemon threads?Medium
111.What are daemon threads? How do they differ from non-daemon threads?
Medium
112.What is thread-local storage? (threading.local())Hard
112.What is thread-local storage? (threading.local())
Hard
113.What are locks, RLocks, and semaphores?Hard
113.What are locks, RLocks, and semaphores?
Hard
114.What is a race condition? How do you prevent it?Medium
114.What is a race condition? How do you prevent it?
Medium
115.What is deadlock? How do you avoid it?Hard
115.What is deadlock? How do you avoid it?
Hard
116.Explain Queue in threading vs multiprocessing.Hard
116.Explain Queue in threading vs multiprocessing.
Hard
117.What is asyncio? How is it different from threading?Hard
117.What is asyncio? How is it different from threading?
Hard
118.What are coroutines in asyncio?Medium
118.What are coroutines in asyncio?
Medium
119.What is the difference between async def and def?Medium
119.What is the difference between async def and def?
Medium
120.What is await keyword? What can you await?Medium
120.What is await keyword? What can you await?
Medium
121.How do you profile Python code?Medium
121.How do you profile Python code?
Medium
122.What is cProfile vs profile?Hard
122.What is cProfile vs profile?
Hard
123.What is the timeit module? How do you use it?Easy
123.What is the timeit module? How do you use it?
Easy
124.How do you measure memory usage of Python objects?Medium
124.How do you measure memory usage of Python objects?
Medium
125.What is sys.getsizeof()? What are its limitations?Hard
125.What is sys.getsizeof()? What are its limitations?
Hard
126.How do __slots__ reduce memory usage?Hard
126.How do __slots__ reduce memory usage?
Hard
127.Why are list comprehensions faster than loops?Medium
127.Why are list comprehensions faster than loops?
Medium
128.What is the difference between map() and list comprehension performance?Hard
128.What is the difference between map() and list comprehension performance?
Hard
129.When should you use generators for performance?Easy
129.When should you use generators for performance?
Easy
130.What is lazy evaluation in Python?Medium
130.What is lazy evaluation in Python?
Medium
131.How does string concatenation affect performance?Easy
131.How does string concatenation affect performance?
Easy
132.Why is ''.join(list) faster than + for strings?Medium
132.Why is ''.join(list) faster than + for strings?
Medium
133.What is the dis module? How do you disassemble Python bytecode?Hard
133.What is the dis module? How do you disassemble Python bytecode?
Hard
134.How do you optimize function calls?Hard
134.How do you optimize function calls?
Hard
135.What is JIT compilation? Does CPython have it?Hard
135.What is JIT compilation? Does CPython have it?
Hard
136.What are type hints? Are they enforced at runtime?Easy
136.What are type hints? Are they enforced at runtime?
Easy
137.What is the typing module?Medium
137.What is the typing module?
Medium
138.What is mypy? How does static type checking work?Medium
138.What is mypy? How does static type checking work?
Medium
139.What are Protocol and TypedDict?Hard
139.What are Protocol and TypedDict?
Hard
140.What is duck typing vs static typing?Easy
140.What is duck typing vs static typing?
Easy
141.What is monkey patching? When is it useful/dangerous?Hard
141.What is monkey patching? When is it useful/dangerous?
Hard
142.How do you patch methods for testing?Hard
142.How do you patch methods for testing?
Hard
143.What is the pickle module? How does serialization work?Medium
143.What is the pickle module? How does serialization work?
Medium
144.What are the security concerns with pickle?Hard
144.What are the security concerns with pickle?
Hard
145.What is json vs pickle for serialization?Easy
145.What is json vs pickle for serialization?
Easy
146.How do you make a class picklable?Hard
146.How do you make a class picklable?
Hard
147.What are __getstate__ and __setstate__?Hard
147.What are __getstate__ and __setstate__?
Hard
148.What is the weakref module? When do you need weak references?Expert
148.What is the weakref module? When do you need weak references?
Expert
149.What are weak dictionaries (WeakKeyDictionary, WeakValueDictionary)?Expert
149.What are weak dictionaries (WeakKeyDictionary, WeakValueDictionary)?
Expert
150.How does Python's with work with file objects?Easy
150.How does Python's with work with file objects?
Easy
151.What is the difference between open() modes: r, w, a, r+, w+, a+?Medium
151.What is the difference between open() modes: r, w, a, r+, w+, a+?
Medium
152.What is the difference between text mode and binary mode?Medium
152.What is the difference between text mode and binary mode?
Medium
153.What is buffering in file I/O?Hard
153.What is buffering in file I/O?
Hard
154.What are io.StringIO and io.BytesIO?Hard
154.What are io.StringIO and io.BytesIO?
Hard
155.How do you handle different encodings in files?Medium
155.How do you handle different encodings in files?
Medium
156.How does dictionary implementation work in Python (hash tables)?Expert
156.How does dictionary implementation work in Python (hash tables)?
Expert
157.What is hash collision? How does Python handle it?Expert
157.What is hash collision? How does Python handle it?
Expert
158.Why are dictionary keys required to be hashable?Hard
158.Why are dictionary keys required to be hashable?
Hard
159.How does list implementation work internally (dynamic arrays)?Expert
159.How does list implementation work internally (dynamic arrays)?
Expert
160.What is list over-allocation?Expert
160.What is list over-allocation?
Expert
161.How does set implementation differ from dictionary?Hard
161.How does set implementation differ from dictionary?
Hard
162.What is the time complexity of dictionary operations?Medium
162.What is the time complexity of dictionary operations?
Medium
163.What is the time complexity of list operations (append, insert, pop)?Medium
163.What is the time complexity of list operations (append, insert, pop)?
Medium
164.How does in operator work for lists vs sets?Easy
164.How does in operator work for lists vs sets?
Easy
165.What is the difference between None, False, and 0?Easy
165.What is the difference between None, False, and 0?
Easy
166.How many objects exist for None in Python?Medium
166.How many objects exist for None in Python?
Medium
167.What is interning? Which types are interned?Hard
167.What is interning? Which types are interned?
Hard
168.How does Python optimize short strings?Hard
168.How does Python optimize short strings?
Hard
169.What is peephole optimization in Python?Expert
169.What is peephole optimization in Python?
Expert
170.How does Python's argument passing work internally?Expert
170.How does Python's argument passing work internally?
Expert