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:

python for data science

Decorator modifies behavior:

python data science

Determining the execution time of a function using decorator:

Case where function returns something:


So, to learn more about decorators in python for data science, you can check this and this as well.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.