Hey @Priyanka,
Python Lambda functions are functions that do not have any name. They are also known as anonymous or nameless functions. The word ‘lambda’ is not a name, but its a keyword. This keyword specifies that the function that follows is anonymous.
A Lambda function is created using the lambda operator and its syntax is as follows:
SYNTAX:
lambda arguments: expression
Python lambda function can have any number of arguments but it takes just one expression. The inputs or arguments can start at 0 and go up to any limit. Just like any other functions, it’s perfectly fine to have lambda functions with no inputs. Therefore, you can have lambda functions in any of the following formats:
EXAMPLE:
lambda : “Specify the purpose”
Here, the lambda function is not taking any arguments.
EXAMPLE:
lambda a1: “Specify the use of a1“
Here, lambda is taking one input which is a1.
Similarly, you can have lambda a1, a2, a3..an.
Let’s take a few examples to demonstrate this:
EXAMPLE 1:
|
a = lambda x: x*x
print(a(3) |
OUTPUT: 9
Have a look at this blog for detailed explanation: https://www.edureka.co/blog/python-lambda/