Python Programming - Decorators
Exercise : Decorators - General Questions
- Decorators - General Questions
31.
What is the purpose of the
@contextlib.asynccontextmanager
decorator?
Answer: Option
Explanation:
The
@contextlib.asynccontextmanager
decorator is used for creating asynchronous context managers, enabling the use of the 'async with' statement in asynchronous code.
32.
What is the primary use case for the
@contextlib.suppress
decorator?
Answer: Option
Explanation:
The
@contextlib.suppress
decorator is used to suppress specified exceptions within a context, allowing the code to continue execution even if those exceptions are raised.
33.
What is the purpose of the
@functools.lru_cache
decorator's maxsize
parameter?
Answer: Option
Explanation:
The
@functools.lru_cache
decorator's maxsize
parameter controls the maximum number of function calls to be cached.
34.
What is the primary use case for the
@contextlib.ExitStack
?
Answer: Option
Explanation:
The
@contextlib.ExitStack
is used for managing a stack of cleanup callbacks, making it useful for managing resources within a context.
35.
What is the primary use case for the
@contextlib.redirect_stdout
decorator?
Answer: Option
Explanation:
The
@contextlib.redirect_stdout
decorator is used to redirect standard output to a specified file or file-like object within a context.
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers