21. How can you remove a decorator from a function in Python? A. By deleting the decorator's code B. By using the @remove_decorator syntax C. By using the @decorator syntax again D. By calling the remove_decorator() function Answer & Solution Discuss in Board Save for Later Answer & Solution Answer: Option C Solution: You can remove a decorator by removing the @decorator syntax from the function.
22. What is a memoization decorator used for? A. To add logging to functions B. To modify function behavior C. To cache function results D. To validate function inputs Answer & Solution Discuss in Board Save for Later Answer & Solution Answer: Option C Solution: A memoization decorator is used to cache the results of a function to improve performance.
23. What is the purpose of the @lru_cache decorator in Python? A. To limit the number of decorator applications B. To cache the last used decorator C. To cache function results with a limited size D. To cache only class methods Answer & Solution Discuss in Board Save for Later Answer & Solution Answer: Option C Solution: The @lru_cache decorator is used to cache function results with a limited size using the Least Recently Used strategy.
24. 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 D. By removing context from code Answer & Solution Discuss in Board Save for Later Answer & Solution Answer: Option C Solution: The @contextmanager decorator allows a function to act as a context manager with the with statement.
25. What is the purpose of the @dataclass decorator in Python? A. To create data visualization B. To add metadata to classes C. To create a class for data manipulation D. To simplify the creation of classes for storing data Answer & Solution Discuss in Board Save for Later Answer & Solution Answer: Option D Solution: The @dataclass decorator simplifies the creation of classes for storing and manipulating data.