Looking into simple function decorators
We will now look at different types of function decorators with an example. We will continue using the ABC Megamart example we looked at in the previous chapter. Each user-defined function in Python can perform a different operation. But what if we want different functions to show specific additional information, no matter what the functions perform? We can do this simply by defining another function that decorates any function that is provided as an input.
Let’s take a look at the following steps to understand this better:
- A function decorator can be defined as follows:
def functiondecorator(inputfunction): def decorator(): print("---Decorate function with this line--- ") ...