8000 add decorator function sample · albin-joseph/python@925c916 · GitHub
[go: up one dir, main page]

Skip to content

Commit 925c916

Browse files
committed
add decorator function sample
1 parent 331fc02 commit 925c916

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
#decorator function is a function which run another function and return the result
2+
import time
3+
4+
def delay_decorator(function):
5+
def wrapper_function():
6+
time.sleep(2)
7+
#Do something before function
8+
function()
9+
#Do something after function
10+
return wrapper_function
11+
12+
@delay_decorator
13+
def say_hello():
14+
print("Hello")
15+
16+
@delay_decorator
17+
def say_bye():
18+
print("Bye")
19+
20+
def say_greetings():
21+
print("How are you")
22+
23+
say_hello()
24+

0 commit comments

Comments
 (0)
0