Creating Python Decorator

Creating Python Decorator

Instructor-svgAl-Mamun Sarkar
Mar 26 , 2020

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

 

  • Share On:
  • fb
  • twitter
  • pinterest
  • instagram