✨ Iterators, Generators & Decorators
Decorators
Wrap functions to add behavior.
A decorator is a function that takes another function and returns an enhanced version. Use @decorator as a shortcut.
def shout(fn):
def wrapper(*args, **kwargs):
return fn(*args, **kwargs).upper()
return wrapper
@shout
def greet(name):
return f"hi {name}"
print(greet("ada")) # HI ADA