Vidyalelo
Python · Q24

Decorators in Depth

Programming · Python · question 24

Q24

How does the @contextmanager decorator facilitate context management?

A.
By creating context managers automatically
B.
By adding new context to existing managers
C.
By wrapping functions with context management behavior
Answer
D.
By removing context from code

Answer: Option C

Solution

Answer: Option C
Solution:
The @contextmanager decorator allows a function to act as a context manager with the with statement.