-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy path44-Decorators.py
More file actions
35 lines (28 loc) · 847 Bytes
/
44-Decorators.py
File metadata and controls
35 lines (28 loc) · 847 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
'''
Author : Jaydatt Patel
Decorators: In Python, decorators are a powerful feature that allows you to modify the behavior of a function or a method. They are a type of higher-order function, meaning they take a function as an argument and return a new function that can enhance or alter the behavior of the original function.
'''
# defining decorator and its wrapper function
def before_decorator(fun):
def wrapper():
fun()
print("Before")
return wrapper
def after_decorator(fun):
def wrapper():
fun()
print("after")
return wrapper
def log_decorator(fun):
def wrapper():
fun()
print("log")
return wrapper
# define main function using decorator
@before_decorator
@after_decorator
@log_decorator
def say_hello():
print("Hello!")
# calling main function
say_hello()