-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path57_Python_Lambda.py
64 lines (42 loc) · 869 Bytes
/
57_Python_Lambda.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
64
# Python Lambda
print("Python Lambda")
print("\nExample 1")
x = lambda d: d * 3
print(x(1))
print(x(2))
print(x(3))
print("\nExample 2")
y = lambda e, f: e + f
print(y(3, 1))
print(y(3, 5))
print(y(2, 5))
print("\nExample 3")
z = lambda g1, g2, g3: g1 + g2 + g3
print(z(1, 2, 3))
print(z(4, 5, 6))
print(z(7, 8, 9))
print("\nUsing inside a function:")
print("\nExample 4")
def function1(n):
return lambda h: h * n
dodouble = function1(2)
print(dodouble(11))
print(dodouble(27))
print(dodouble(50))
print(dodouble(512))
print("\nExample 5")
def f2(n):
return lambda i: i * n
tripler = f2(3)
print(tripler(3))
print(tripler(9))
print(tripler(15))
print("\nExample 6")
def myfunction(n):
return lambda j: j * n
mydoubler = myfunction(2)
mytripler = myfunction(3)
print(mydoubler(2))
print(mydoubler(5))
print(mytripler(5))
print(mytripler(10))