lambda in python by R4R Team

-In Python, anonymous function means that a function is without a name. As we already know that def keyword is used to define the normal functions and the lambda keyword is used to create anonymous functions.

Syntax-

lambda argument:expression

- it return the expression part.


program-

#add two number by lambda number
print("Addition of number by lambda ")
add=lambda x,y:x+y

print(add(3,4))
print(add(1,-1))
print(add(3,0))

#find cube of number
print("Cube lambda function")
cube=lambda x:x**3

print(cube(3))
print(cube(5))
print(cube(10))


output-

Addition of number by lambda
7
0
3
Cube lambda function
27
125
1000


-In this program, we make lambda function of addition in which we take two arguments x and y, and return the expression x+y.
- and lambda function of cube in which we take one argument and return the cube of the number.




Leave a Comment:
Search
Categories
R4R Team
R4Rin Top Tutorials are Core Java,Hibernate ,Spring,Sturts.The content on R4R.in website is done by expert team not only with the help of books but along with the strong professional knowledge in all context like coding,designing, marketing,etc!