A callable is a function-like object, meaning it's something that behaves like a function. The primary types of callables in Python are functions and classes, though other callable objects do exist.
In Python, you can pass functions (as an argument) to another function. Some of Python's built-in functions actually expect functions to be given as one or more of their arguments to call them later.
Functions in Python can be defined within another function.
A decorator is a callable (usually a function though sometimes a class) that accepts either a function or a class and returns a new function or class that wraps around the original one.
A decorator is a function that accepts a function and returns a function. That's true for function decorators at least.
Python has a wide range of built-in decorators that turn complex logic into clean abstractions, like caching function calls, reducing redundancy, and customizing class behavior.
I highly recommend all decorator functions use functools.wrap to help the decorator's replacement function pretend it's the original decorated function. Well-behaved Python decorators tend use this.
If you want to make a decorator that's customizable, make a decorator that accepts arguments. That's really just a function that accepts arguments and returns a decorator that uses those arguments.
Decorators aren't just for functions! Class decorators are functions that accepts a class and return a class. They usually modify and then return the original class instead of making a new class.
Decorators are not necessarily implemented using functions. You could also make a decorator using a class, or even an instance of a class. Any callable could be a decorator.
Decorators can return anything, including non-functions and non-classes, which is rare but occasionally useful.
Functions are objects in Python, and they can store attributes. Function attributes are usually used to store metadata related to a function.
Python resolves variable names through its four scope levels: local, enclosing, global, and built-in.
Some decorators with or without arguments. How is that possible?!
My name is Trey Hunner. I publish new Python articles and screencasts every week through Python Morsels. If you want to learn something new about Python every week, join Python Morsels!