Because it is important to understand how functions work when we deal with decorators, we'll take a quick look at them. First, we need to remember that everything in Python is an object, including functions.
Functions are created in Python by using the def
keyword and naming the function; input arguments are optional. Following is a basic function for reference:
def func_foo(): pass
>>> def first_func(val): ... print(val) ... >>> new_name = first_func >>> first_func("Spam!") Spam! >>> new_name("Spam too!") Spam too!
- Functions can be used as arguments for other functions. Some Python built-in functions, such as
map
andfilter
, use this feature to do their jobs:
>...