Creating Python Decorator

Author: Al-mamun Sarkar Date: 2020-03-26 07:36:05

Creating python decorator. The following code shows how to create a custom decorator in the Python programming language.

Code:

def print_int(my_function):

    def any_function():
        return my_function

    return any_function()


@print_int
def get_int_as_str(number):
    print(str(number))
    return


get_int_as_str(130)

 

Output:

130