In the case of Python for data science, functions are taken as first class objects. This implies that:
- Functions are objects. They can be reference, we can pass to any variable, and can return it from other functions.
- We can define these functions inside other functions. Also, they can be pass in the form of argument to other functions.
Decorators are useful tools for the modification of the behavior of function and class. Decorators also allow to wrap one function with another which extends the behavior of wrap functions without any permanent modifications.
In the case of decorators, functions are taken as arguments for another function, and then it is call inside wrapper function.
Syntax for using Decorator:
Decorator modifies behavior:
Determining the execution time of a function using decorator:
Case where function returns something: