-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathprog26_decorators.py
63 lines (43 loc) · 996 Bytes
/
prog26_decorators.py
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
'''
------- Example -1 -----------------
'''
# def myfunc1():
# print("Hello, I am Ram")
# myfunc2 = myfunc1
# del myfunc1
# myfunc2()
'''
------- Example -2 -----------------
You can return a Function using a function. Function can return function.
'''
# def myfunction_1(num):
# if num == 0:
# return print
# if num == 1:
# return sum
# a = myfunction_1(0)
# print(a)
# a = myfunction_1(1)
# print(a)
'''
------- Example -3 -----------------
Pass function as an argument of a function
'''
# def myfunction_2(myfunction_1):
# myfunction_1("Hello Python Decorators")
# myfunction_2(print)
'''
------- Example -4 -----------------
Decorator
'''
def dec1(func1):
def nowexec():
print("Execute Now")
func1()
print("Executed")
return nowexec
@dec1
def Ram_function():
print("Ram is a good boy")
#Ram_function = dec1(Ram_function)
Ram_function()