Problem Statement
What is the primary purpose of a decorator in Python?
Explanation
Decorators are higher-order callables that take a function and return a wrapped function. They enable cross-cutting concerns like logging, timing, caching, and access control.
This keeps core logic clean while applying consistent policies in a reusable way.
Code Solution
SolutionRead Only
def log(fn):
def wrap(*a, **k):
print('call', fn.__name__)
return fn(*a, **k)
return wrap
@log
def add(x,y): return x+y