-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLambda.py
More file actions
36 lines (18 loc) · 742 Bytes
/
Lambda.py
File metadata and controls
36 lines (18 loc) · 742 Bytes
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
# this program shows the usage of the lambda function in python
# the lambda function refers to any anonymous function
# syntax :
# lambda arguments : expression
# wwhen to use lambda function :::: when u need an anonymous function for a short period of time or when u ned to pass an function as a argument to another function
add = lambda a,b,c,d : a + b + c + d
print(add(1,2,3,4))
sub = lambda a,b : a - b
print(sub(10,11))
def myfunc(x):
return lambda n: n*x
y = myfunc(20)
print(y(2))
say_hello = lambda : print("hello")
say_hello()
my_list = [1,2,3,4,5,6,7,8,9,10]
new_list = list(filter(lambda x: x%2==0,my_list)) # the filter function takes two arguments one function and another list
print(new_list)