Skip to content

Commit 8dd3d16

Browse files
committed
lexical_closure
hardcoding_lambda
0 parents  commit 8dd3d16

File tree

2 files changed

+27
-0
lines changed

2 files changed

+27
-0
lines changed

hardcoding_lambda.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
a = list(filter(lambda x: x % 2 == 0, range(16)))
2+
print(a)
3+
4+
b= [x for x in range(16) if x%2==0]
5+
print(b)

lexical_closure.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
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))

0 commit comments

Comments
 (0)