By anonymous or lamda function and anonymous function means there is a function which has got no name.
So how do you define anonymous function or Landen function in Biton?
We shall be discussing that one in this session.
So in Python, the anonymous function is a function that is defined without having any name.
So in normal function definitions, we use that the key word there is a defined tool and on the other
end in Python, the anonymous functions are used using the lambda keyword.
So hence anonymous functions are also called the lambda function.
So in case of anonymous functions, there will be no name.
So we are not using the key word def that is a defined and here will be using the keyword.
That is that lambda.
So I think it would be better to let us go for one demonstration to show you how to write the anonymous
functions and then the lambda functions in our python coding.
While defining ordinary functions, we use the key word, if there is a defined but in case of LAMDA
function, we shall be using the key word lambda.
So here we are having some set of examples to clear your doubts and to know that what is an anonymous
function or a lambda function?
So here you can find that lambda X, so X will be the input and it returns X start to that because the
returns are double up to X and that has been assigned to a.
So in Python, anonymous function is a function that is defined without the name and it is defined by
the key word lambda.
So now if we pass this 10 as input argument to this E, then obviously I'm supposed to get double often.
So if I put my code, I can find that double of ten is 20.
So here X is input and it returns.
This external to that is a double of X here.
So let us go for the another one.
So making a new list by taking only the event numbers from the old list.
So here is my old list.
So it is my, my list and it is having are set up.
Numbers are there and here you are using one method, one function that is known as a filter function,
which is called with all the items in the list that is on my list.
It will be it will be working on all the items of this my list, and it will create a new list which
will be returned, which contains items for which the function evaluates.
True.
That means that we are having one condition.
The condition will be true if X is an even number, because X percent D2 means that the remainder of
the division of by two.
If it is zero, that means if the number X is even number, then X percent is will be equal to zero,
then the respective X will be returned.
So now that will create a new list.
So if I bring that new list, it will print here for six, eight and 12 respectively.
So let us go for the output here.
So if I execute on finding that the new list is having the value for six, eight and 12 because they
are the only event numbers in this my list.
So this filter is actually dealing with those numbers which will satisfy this condition.
That is X percentage is is equal to zero and it will operate on a new list on my list and it will produce
output in the new list here.
So let's go for another example of this lambda function.
So here you can see that a program to double each item in a list using the map.
So here we are losing the method map here.
So my list is having one, five, four, six, eight, 11, three and very arbitrary numbers we have
mentioned here.
Now we are having this lambda, which will take this X and it will return to Stridex and the values
of X will be taken individually from this list that is on my list here and that will be mapped.
So here we are using this method to map here, which will double each item in a list using this map
method.
And here the outcome is being done, the typecasting to list.
So now the new list will be getting the list as well.
So now what will be the output?
So let's go for the execution.
You can find that all the members in this particular list, there is a list, members have got doubled
and that has been assigned to the new list.
So this map is actually mapping this this lambda function to each and every element of this.
My list and its outcome will be has been done typecast with this list method.
And so that new list has been formed.
And later we have printed the new list as well.
So in this example, we have shown you that how to define lambda.
That is the anonymous function in our Bitan.
Thanks for watching this video.