ANONYMOUS FUNCTION (or) LAMBDA FUNCTION
- Creating a function without any name is called as anonymous function
- In python, the anonymous function can be created with help of lambda keyword
- The reserved word lambda takes any number of the arguments and returns an evaluated expression value
- It is important to note that the anonymous function can be created without the use of the def keyword.
IV. ANONYMOUS FUNCTION
(ganesh.py)
1. SOURCE CODE
# anonymous function
squ=lambda a: a*a
# calling anonymous function
k=squ(5)
# print the result
print(“Square is : “,k)
2. OUTPUT
V. ANONYMOUS FUNCTION – (CONTINUE)
(ganesh.py)
1. SOURCE CODE
# anonymous function 1
rect=lambda a,b:(a*b)
# calling anonymous function 1
r1=rect(10,5)
# anonymous function 2
circle=lambda r:(3.14*r*r)
# calling anonymous function 2
r2=circle(10)
# print the result
print(“Area of the rectangle : “,r1)
print(“Area of the circle : “,r2)
2. OUTPUT