Comprehensive Final Exam (Qns & Ans)
2025
Question 1 (Multiple Choice)
Question:
Which built-in decorator in Python is specifically designed to
optimize function performance by caching results for repeated
calls?
A) `@abstractmethod`
B) `@lru_cache`
C) `@property`
D) `@staticmethod`
Correct ANS:
B) `@lru_cache`
©2025
, Rationale:
The `@lru_cache` decorator (from the `functools` module) caches
the return values of function calls so that subsequent calls with the
same arguments bypass redundant computation, thereby
improving performance.
---
Question 2 (Fill in the Blank)
Question:
In Python, the technique of modifying classes at runtime—
allowing changes to a class’s behavior during execution—is often
implemented using a ________ .
Correct ANS:
metaclass
Rationale:
A metaclass is a class of a class in Python, which allows you to
control the creation and behavior of classes. It is a powerful tool
for advanced metaprogramming and dynamic modification of
class properties.
©2025
,---
Question 3 (True/False)
Question:
True/False: Python natively supports multiple inheritance,
allowing a class to inherit from two or more base classes, with the
Method Resolution Order (MRO) determining the order in which
base classes are searched.
Correct ANS:
True
Rationale:
Python fully supports multiple inheritance, and its MRO (utilizing
the C3 linearization algorithm) ensures a consistent order in
which methods and attributes are inherited, avoiding ambiguity.
---
Question 4 (Multiple Response)
Question:
©2025
, Select all libraries or frameworks that enable asynchronous
programming in Python:
A) `asyncio`
B) Twisted
C) Tornado
D) `multiprocessing`
E) Gevent
Correct ANS:
A, B, C, E
Rationale:
`asyncio`, Twisted, Tornado, and Gevent are all frameworks that
support asynchronous I/O and event-driven programming in
Python. The `multiprocessing` module enables parallel execution
of processes but is not primarily designed for asynchronous
programming.
---
Question 5 (Multiple Choice)
Question:
©2025