Skip to content

Commit f4c0764

Browse files
authored
Merge pull request #4283 from raulG91/raulG91
#24 - Python
2 parents 9bb0b37 + bee60e4 commit f4c0764

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
#Basic decorator
2+
def my_decorator(function):
3+
def my_wrapper(*args,**kwargs):
4+
print("Initialize wrapper")
5+
result = function(*args,**kwargs)
6+
print("Finishing wrapper")
7+
return result
8+
9+
return my_wrapper
10+
11+
@my_decorator
12+
def suma(a,b):
13+
return a + b
14+
15+
print(suma(2,3))
16+
17+
#Extra
18+
def my_decorator2(function):
19+
execution = 0
20+
def my_wrapper2(*args,**kwargs):
21+
nonlocal execution
22+
execution += 1
23+
function(*args,**kwargs)
24+
return execution
25+
return my_wrapper2
26+
27+
@my_decorator2
28+
def multiply(value1,value2):
29+
print(f'Value of multiplication {value1 * value2}')
30+
31+
print(f'Number of executions {multiply(4,2)}')
32+
print(f'Number of executions {multiply(8,7)}')

0 commit comments

Comments
 (0)