June 2017
Beginner to intermediate
274 pages
6h 49m
English
Python has a special syntax for applying a decorator to a function, using the @ syntax. With this syntax, we just write an @ symbol, followed by an expression that evaluates to a decorator function. We put that on the line right before the definition of the function we want to decorate, as shown in the following code example:

This syntax means that as soon as we're done defining the function, we call the decorator function on it and then assign the return value of the decorator to the variable that would have contained the function, as shown here:
Read now
Unlock full access