Lambda Function In Python
In this tutorial, we will give you a brief introduction to the lambda function. It is not necessary to know about lambda function. without knowing about this lambda function the program can be made. It is a short way to generate functions and do other things in programming. We will also see an example of Lambda function in Python.
Mainly the lambda function is called an anonymous function that is without a name. The lambda function may contain one or more arguments but still has only one expression. The basic syntax of lambda function in the comment section with an example is given below :
Syntax of Lambda function
# lambda arguments: expression x= lambda y : y*5 print(x(5))
Example of lambda function in Python
We have read that the lambda function takes a number of arguments lets cross-check it;
a = lambda x,y,z: (x+y)*z print(a(2,3,4)) # a takes the values of x ,y ,z respectively
Now, we can use lambda function instead of def keyword . the def keyword is used to define a function as:
def cubic(x): return x*x*x cubic(5)
This thing can be done by using lambda function as:
y=lambda x: x*x*x print(y(5))
Thanks for reading.
For more information about the lambda function, you can visit the following links: