- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLambda.py
More file actions
Latest commit
36 lines (18 loc) · 742 Bytes
/
Copy pathLambda.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=lambdaa,b,c,d : a+b+c+d
print(add(1,2,3,4))
sub=lambdaa,b : a-b
print(sub(10,11))
defmyfunc(x):
returnlambdan: 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(lambdax: x%2==0,my_list)) # the filter function takes two arguments one function and another list
print(new_list)