Decorators
Last updated
Last updated
are just for .
Example:
The @vowel_counter
line is "decorating" the process_doc
function with the vowel_counter
function. vowel_counter
is called once when process_doc
is defined with the @
syntax, but the wrapper
function that it returns is called every time process_doc
is called. That's why vowel_count
is preserved and printed after each time.
Python decorators are just another (sometimes simpler) way of writing a higher-order function. These two pieces of code are identical: