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

1.What is Python's dynamic typing? How does it work internally?

2.Explain Python's memory management and reference counting.

3.What is the difference between is and ==? Give examples with strings and integers.

4.Why are small integers cached in Python? What is integer interning?

5.What is string interning in Python?

6.Explain Python's garbage collection mechanism (generational garbage collection).

7.What are the differences between mutable and immutable types? Why does it matter?

8.What is the id() function and what does it return?

9.Explain the concept of 'everything is an object' in Python.

10.What is the difference between del and remove()?

11.How does Python's pass by object reference work?

12.What is the difference between copy() and deepcopy()?

13.Explain the sys.intern() function.

14.What happens when you modify a tuple containing a list?

15.Why can't you use a list as a dictionary key but can use a tuple?

16.What is __pycache__ folder? What are .pyc files?

17.What is the difference between .py and .pyc files?

18.How does Python's bytecode compilation work?

19.What is the Python interpreter? How does it execute code?

20.Explain the difference between CPython, PyPy, Jython, and IronPython.

21.What are descriptors in Python? Explain with examples.

22.What is the difference between __getattr__, __getattribute__, and __get__?

23.Explain __setattr__, __delattr__, and __delitem__.

24.What are slots (__slots__)? When and why to use them?

25.How do __slots__ improve memory usage and performance?

26.What is the difference between __new__ and __init__?

27.When would you override __new__ instead of __init__?

28.What are metaclasses? Give practical use cases.

29.How do you create a singleton using metaclasses?

30.What is type() as a metaclass?

31.Explain the __call__ method and callable objects.

32.What is the difference between __str__ and __repr__?

33.When does Python call __repr__ vs __str__?

34.What are magic methods (dunder methods)? List 15 important ones.

35.Explain __enter__ and __exit__ methods.

36.What is the @property decorator? How is it different from getters/setters?

37.How do you create read-only properties?

38.What is property deletion using @property.deleter?

39.Explain method resolution order (MRO) with multiple inheritance.

40.What is the C3 linearization algorithm?

41.What is a closure? How does it capture variables?

42.Explain the LEGB rule in Python scope.

43.What are the differences between local, global, and nonlocal keywords?

44.How do decorators work internally?

45.How do you create a decorator that accepts arguments?

46.What is functools.wraps? Why use it in decorators?

47.How do you stack multiple decorators?

48.What is the difference between @staticmethod and @classmethod?

49.When would you use @classmethod instead of __init__?

50.How do you create class decorators?

51.What is the difference between function decorators and class decorators?

52.Explain functools.lru_cache decorator.

53.What is functools.partial? Give use cases.

54.How do you create a decorator that works with and without arguments?

55.What are context manager decorators (@contextmanager)?

56.What is the difference between generator and iterator?

57.How does the yield keyword work?

58.What is yield from? When to use it?

59.Explain generator expressions vs list comprehensions for memory.

60.What happens when you call next() on an exhausted generator?

61.How do you send values to a generator using send()?

62.What is the throw() method in generators?

63.What is the close() method in generators?

64.How do you create an infinite generator?

65.What are coroutines? How are they related to generators?

66.Explain the iterator protocol (__iter__ and __next__).

67.How do you make a class iterable?

68.What is itertools module? Explain 5 useful functions.

69.What is the difference between iter() with one vs two arguments?

70.How do you chain iterators?

71.What is a context manager?

72.How does the with statement work?

73.How do you create a custom context manager using class?

74.How do you create a context manager using @contextmanager?

75.What is contextlib.ExitStack?

76.Can context managers suppress exceptions? How?

77.What happens if an exception occurs in __enter__?

78.What are the return values of __exit__ method?

79.How do you nest multiple context managers?

80.What is contextlib.closing?

81.What is the difference between except Exception and bare except?

82.Why should you avoid bare except clauses?

83.What is exception chaining? Explain raise...from.

84.What is the difference between raise and raise Exception?

85.How do you re-raise an exception?

86.What is sys.exc_info()?

87.What are exception groups (Python 3.11)?

88.How do you create custom exception classes?

89.What is the finally clause? When does it execute?

90.What is the else clause in try-except? When does it run?

91.What is the difference between a module and a package?

92.What is __init__.py file? Is it still needed in Python 3.3+?

93.What are namespace packages?

94.What is the difference between absolute and relative imports?

95.How does Python's import system work?

96.What is sys.path? How can you modify it?

97.What is importlib? How do you import dynamically?

98.What is the difference between import module and from module import *?

99.What does if __name__ == '__main__' do?

100.How do you reload a module? Why is reload() dangerous?

101.What are circular imports? How do you avoid them?

102.What is __all__ variable in modules?

103.How do you create a package with subpackages?

104.What is the difference between site-packages and dist-packages?

105.How does virtual environment isolation work?

106.What is the GIL (Global Interpreter Lock)? Why does it exist?

107.How does GIL affect multithreading?

108.When does GIL release? (I/O operations, time)

109.What is the difference between threading and multiprocessing?

110.When would you use threading vs multiprocessing?

111.What are daemon threads? How do they differ from non-daemon threads?

112.What is thread-local storage? (threading.local())

113.What are locks, RLocks, and semaphores?

114.What is a race condition? How do you prevent it?

115.What is deadlock? How do you avoid it?

116.Explain Queue in threading vs multiprocessing.

117.What is asyncio? How is it different from threading?

118.What are coroutines in asyncio?

119.What is the difference between async def and def?

120.What is await keyword? What can you await?

121.How do you profile Python code?

122.What is cProfile vs profile?

123.What is the timeit module? How do you use it?

124.How do you measure memory usage of Python objects?

125.What is sys.getsizeof()? What are its limitations?

126.How do __slots__ reduce memory usage?

127.Why are list comprehensions faster than loops?

128.What is the difference between map() and list comprehension performance?

129.When should you use generators for performance?

130.What is lazy evaluation in Python?

131.How does string concatenation affect performance?

132.Why is ''.join(list) faster than + for strings?

133.What is the dis module? How do you disassemble Python bytecode?

134.How do you optimize function calls?

135.What is JIT compilation? Does CPython have it?

136.What are type hints? Are they enforced at runtime?

137.What is the typing module?

138.What is mypy? How does static type checking work?

139.What are Protocol and TypedDict?

140.What is duck typing vs static typing?

141.What is monkey patching? When is it useful/dangerous?

142.How do you patch methods for testing?

143.What is the pickle module? How does serialization work?

144.What are the security concerns with pickle?

145.What is json vs pickle for serialization?

146.How do you make a class picklable?

147.What are __getstate__ and __setstate__?

148.What is the weakref module? When do you need weak references?

149.What are weak dictionaries (WeakKeyDictionary, WeakValueDictionary)?

150.How does Python's with work with file objects?

151.What is the difference between open() modes: r, w, a, r+, w+, a+?

152.What is the difference between text mode and binary mode?

153.What is buffering in file I/O?

154.What are io.StringIO and io.BytesIO?

155.How do you handle different encodings in files?

156.How does dictionary implementation work in Python (hash tables)?

157.What is hash collision? How does Python handle it?

158.Why are dictionary keys required to be hashable?

159.How does list implementation work internally (dynamic arrays)?

160.What is list over-allocation?

161.How does set implementation differ from dictionary?

162.What is the time complexity of dictionary operations?

163.What is the time complexity of list operations (append, insert, pop)?

164.How does in operator work for lists vs sets?

165.What is the difference between None, False, and 0?

166.How many objects exist for None in Python?

167.What is interning? Which types are interned?

168.How does Python optimize short strings?

169.What is peephole optimization in Python?

170.How does Python's argument passing work internally?