Tech_Interview_Prep

Decorators & Context Managers

Wrapping a function's behavior without changing its code, and guaranteeing setup/teardown runs even when something fails.

Q1.What is a decorator in Python?

Q2.What does the `with` statement guarantee for a context manager, even if an exception occurs inside the block?

Q3.What two dunder methods must a class implement to be used as a context manager?

Q4.What does `functools.wraps` do when writing a decorator?