Python Programming - Decorators
Exercise : Decorators - General Questions
- Decorators - General Questions
21.
What is the purpose of the
@functools.retry decorator?
Answer: Option
Explanation:
The
@functools.retry decorator is used to retry a function with a specified delay in case of failure.
@functools.retry(max_retries=3, delay=2)
def unstable_function():
# Function implementation
22.
What is the purpose of the
@functools.singledispatchmethod decorator?
Answer: Option
Explanation:
The
@functools.singledispatchmethod decorator in Python is used to enable function overloading based on the type of the first argument within a class.
23.
What does the
@functools.cached_property decorator do when applied to a method inside a class?
Answer: Option
Explanation:
The
@functools.cached_property decorator caches the result of a method and returns the cached value on subsequent calls.
24.
How does the
@functools.singledispatch decorator differ from @functools.singledispatchmethod?
Answer: Option
Explanation:
@functools.singledispatch is used for functions, providing a mechanism for function overloading based on argument types, while @functools.singledispatchmethod serves the same purpose but is specifically designed for methods within a class.
25.
What is the primary purpose of the
@functools.cached_property decorator?
Answer: Option
Explanation:
The
@functools.cached_property decorator is used to cache the result of a method and return the cached value on subsequent calls, improving performance by avoiding redundant computations.
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers