Lambda Functions

Lambda functions are small types of anonymous functions,where we can write short code and get enough output.

Syntax
Lambda argument:expression

Question 1 Finding the Square of any number using lambda function.

Output

Python 3.8.4 (tags/v3.8.4:dfa645a, Jul 13 2020, 16:30:28) [MSC v.1926 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> square=lambda x:x**2
>>> square(34)
1156
>>> square(335)
112225
>>>

Question 2 Write a program to find the cube of any number using the lambda function.

Output

Python 3.8.4 (tags/v3.8.4:dfa645a, Jul 13 2020, 16:30:28) [MSC v.1926 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> cube=lambda x:x**3
>>> cube(343)
40353607
>>> cube(32)
32768
>>>

Question 3 Write a program to find the area of a circle using the lambda function.

Output

Python 3.8.4 (tags/v3.8.4:dfa645a, Jul 13 2020, 16:30:28) [MSC v.1926 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> circul_area=lambda x:22/7*x*x
>>> circul_area(343)
369754.0
>>> circul_area(34)
3633.1428571428573
>>> circul_area(20)
1257.142857142857
Subscribe Now