Decorators in Python
A decorator wraps a function to add behaviour without rewriting its core. @my_decorator above a def is sugar for f = deco(f). Uses: log calls, time a function, check login, cache. Under the hood it is a function that takes a function and returns a new one.
Don’t start with functools.wraps on day one unless they ask. Explain f = deco(f), then one use: timing print. Keep the wrapped function’s job the same.
Decorators in Python — output — HI ASHA. @shout wraps greet and uppercases the result.
f = deco(f) mental model.