Decorator

Applies to: python

A decorator wraps a function to add behavior (timing, caching, logging) without changing its body, applied with @name above the definition. functools.lru_cache is a decorator that adds memoization.

@lru_cache          # wraps fib with a cache
def fib(n): ...

See also: function, lambda, memoization