Skip to main content

Python Decorators? meh...

Updated 1 min readMarkdown

In the following snippet, ...

The 'print_name' function becomes the input of the 'decorate' decorator. This is possible because Python considers its functions as First Class Citizens.
In other words, functions can be assigned to variables and passed as arguments.

def decorate (the_function_to_be_decorated):
    def the_function_after_the_decoration (arguments):
        print("some decoration before calling the function")
        the_function_to_be_decorated(arguments)
        print("some decoration after calling the function")

    return the_function_after_the_decoration

@decorate
def print_name (name):
    print("Hi, ", name)

print_name("Hamza Mateen")

Output

I hope you enjoyed it, and learned it in a func way!

About the author

  • Web developer with expertise in React, Flask, automation, and a passion for exploring diverse programming languages and computing paradigms.

No comments yet. Be the first to comment.