Decorator:
the decorators are used to modify the behavior of function or class. In Decorators, functions are taken as the argument into another function and then called inside the wrapper function.
This blog has content related to python programing language and Automation with python and hacker rank solutions , leet code solution
def
shout(text):
return
text.upper()
def
greet(func):
# storing the function in a variable
greeting
=
func(
"Hi, I am created by a function passed as an argument."
)
print
(greeting)
greet(shout)
Output:
HI, I AM CREATED BY A FUNCTION PASSED AS AN ARGUMENT.
In the above example, the greet function takes another function as a parameter (shout ). The function passed as an argument is then called inside the function greet
Comments
Post a Comment