Skip to content

Commit 2b94a32

Browse files
committed
first exp of decorastors
1 parent 14b06f6 commit 2b94a32

File tree

3 files changed

+29
-32
lines changed

3 files changed

+29
-32
lines changed

decorator.py

+17-10
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,19 @@
1-
def cheaker(func):
2-
def wrapper(x, y):
3-
if y == 0:
4-
return print("error zeroo division :(((")
5-
else:
6-
return func(x, y)
1+
def strong(func):
2+
def wrapper():
3+
return '<strong>' + func() + '</strong>'
74
return wrapper
8-
@cheaker
9-
def divider(x , y):
10-
print(x/y)
115

12-
divider(2,0)
6+
7+
8+
def emphasis(func):
9+
def wrapper():
10+
return '<em>' + func() + '</em>'
11+
return wrapper
12+
13+
14+
@strong
15+
@emphasis
16+
def greet():
17+
return 'hello'
18+
19+
print(greet())

decorator_exp1.py

Whitespace-only changes.

lexical_closure.py

+12-22
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,12 @@
1-
def adder(x):
2-
def add(y):
3-
return x + y
4-
return add
5-
6-
a1 = adder(3)
7-
print(a1(13))
8-
9-
class adder_class():
10-
def __init__(self, x):
11-
self.x = x
12-
def __call__(self, y):
13-
return self.x + y
14-
15-
a2 = adder_class(4)
16-
print(a2(3))
17-
18-
19-
def add_lam(n):
20-
return lambda x :x + n
21-
a3 = add_lam(34)
22-
print(a3(12))
1+
def uppercase(func):
2+
def wrapper():
3+
original_result = func()
4+
modified_result = original_result.upper()
5+
return modified_result
6+
return wrapper
7+
8+
9+
def uppercase1(func):
10+
def wrapper():
11+
return func()
12+
return wrapper

0 commit comments

Comments
 (0)