 expressions in Python. So, what exactly an outcome plan for this video? So, after the watching this video, the audience would be able to use lambda expressions in Python. In this hands-on session, what we will be looking into this is we will be more focusing on syntax writing lambda expression. So, let us define a function. So, what the function would do is given a variable, it would just increment the value of that variable by 2. So, I will name the function as increment by 2 and I will provide a variable. So, this method will always return variable plus 2. So, now if I check the output of this method and if I pass 2 value here, you can guess the output. Let me run this code now. So, you can see the output of the code is 4 because I have a method which upon passing a variable which will be returning a variable whose value is incremented by a 2. Now, this same code, what I will be doing here is let me prepend it with a small string here. Let us execute this once again. So, the function called the values 4. Now, the exact function which we wrote in form of Python function syntax, we can also write it in form of a lambda. So, generally a syntax of lambda goes in this way. So, we write a word lambda and usually lambda is assigned to some variable here. Then I define an argument this lambda expression would be taking. So, these arguments here. So, generally these arguments here are equivalent to function arguments. For example, here I am passing where. So, this is one argument here. So, here my lambda would also take one argument and had this method had two arguments like wherever and where to I can also do the same thing here in lambda syntax when I am specifying the arguments. Then once I specify the arguments for this lambda and after putting a colon I need to have an expression here which might involve all the arguments or some of the arguments of this lambda or it can be in any expression which returns a value. So, for example, here I can do something for example, ARGS plus 2 or some kind of operation here. So, instead of writing something what we will call it as we call it an expression. Now, in Python it is sometimes there is a lot of controversial discussion like what exactly are expressions and what exactly are statements. So, in a quick layman's word what I can tell you is here whenever I use the word expression I mean expression or some kind of operation here which usually returns a value. So, as a thumb we can roughly in a layman's word we can just stick to this definition. Remember it cannot include some statements like if statement or some with some kind of Python set of Python operations which do not return a value. So, given a syntax now let us write the syntax definition by converting the method increment by 2 into lambda. So, let us do it and we will call it as INC by 2 this would be the name of my lambda is equal to now I am converting that into lambda lambda is a standard it is a keyword it is not a some variable name or it is a standard keyword and here I am passing the argument where and what will happen this where so it is always where plus 2. So, this is the lambda INC by 2. So, now if I want to call that I will take the exact method here and instead of function call what we will do now we will call it by lambda here. So, here and instead of increment by 2 now what I will do is I will do it called as INC by 2. So, now if I execute this you can see that it has also executed lambda call 4. Now very best use of lambda is when we want to use custom sorting. So, let us call let us have a list and we will call them as sample numbers and I will put some values here for 5 and 0 minus 3 and and what I want is I want to sort this array and we all know that to sort an array we do have some list dot sort, but we do not use it because it does a in place sorting we want some sorting without modifying the original we have always use sorted. So, to the sorted we will provide a sample numbers. Now, if I check the output of this you can see that it is it sorted. Now, here my recommend now you can just observe the output the output is ordered it is it is sorted in ascending order where like lower values to higher. What if I want to override the default sorting order by sorted method and I want this sorting to happen from higher value to lower. So, in short I want a descending ordered sort. So, what should I do in that case what we do is we write the lambda here. So, same call goes here and the second argument is the key which is actually a function we are supposed to give a function here. So, we have two options either you write a function and provide the function or you mention a lambda here. So, what I will do is I will say lambda say a variable and what I want here is. So, since I want to reverse it the quick way to calculate the max and give the subtraction of that. So, what I will do is I will call it max. So, max gives me the maximum of number in a list. So, I have a list of sample numbers and I will say minus where. So, this would effectively ensure that I get a keys in descending order lambda max minus where let me put this in a bracket. I think maybe I am missing some brackets here and I need to close the print. So, I have closed the print now let me just show this everything one screen. So, this is how it looks when I write it. And here I will put a keyword sorting in. So, let us check the output. So, it should give me values from 12 to so on to minus 3. Do you see that? Yes. So, now we are able to sort the list in descending order and why it was able to sort it in descending order because we gave a key argument to it and instead of writing a method and providing the method name here we relied on lambda. So, lambdas are some kind of we can relate them to some kind of functions which do not have any name. So, I can explain what happens everything for each and every element of sample numbers the lambda is called where each element of list takes the takes place of that where. So, the one goes to then the max of sample is 12 minus 1 that ensures what is the difference given that ensures that the list is sorted in descending order. So, wherever we need to pass a quick methods where it is not much important to rely on name, but we just mean a small work around trick we usually rely on lambda. But the true uses of lambda is where we some where it is needed a scenario where developers are more interested in writing a function wrappers and also using methods like map, reduce and filter and we will be looking that into some other video. So, this is it for this video here as far as this hands on session is considered. So, I would like to try one thing. So, for example, what would happen what would happen here I n c by 2 for example, I have lambda here what would happen if I provide multiple expressions can I have a multiple x for example, if I say let us before before going for multiple expressions let us do one thing. Can I have multiple variables and it was like where plus 2 what do you think will it change the output here. So, if I execute this code now. So, lambda takes exactly two arguments, but given one. So, now you it is like a normal method call wherein if you have a method with two arguments you have to provide both arguments unless you define the other argument is a default arguments or multiple arguments, but this is a good indication that okay lambdas are exactly they work like a methods. So, now what you need to do is you need to provide two parameters fine. So, I am providing the third parameter on argument. So, now if I execute you should see that it is working fine, but remember I had only use one expression. What do you think you can I use multiple expressions here for example, if I say where 2 plus 1 is it possible here. So, if you run this what you will see that you will you will find an error where where 2 is not defined. So, what is effective it is telling us the lambda expression shall not contain more than one expression. And if any need arises for such multiple calculation instead of this one for example, we can do this we can do this where 2 less 2 it is a quick work around. See remember these are two operations, but what I am doing is I am actually returning to let me check this I do not think it yes. Now, you can see that function call and here I have a lambda call. Remember it is a one single expression you might think we have multiple expressions that no overall this is an expression of expressions, but overall it is a one single expressions into this video I would like to put a question like does a lambda allow multiple expressions. You can pause the video I can watch the video from beginning and you can guess the answer, but the right answer for this question is no lambda does not allow multiple expressions in as a part of this video I refer to the following links which acts as a bibliography of this video and that is it for this video. Thank you.