I donā€™t understand lambadas at all. Please help! | Sololearn: Learn to code for FREE!
Novo curso! Todo programador deveria aprender IA generativa!
Experimente uma aula grƔtis
+ 1

I donā€™t understand lambadas at all. Please help!

8th Jul 2022, 1:12 PM
Gabriel Burchfield
4 Respostas
+ 1
Our lambda function is now > lambda x, y: x + y How to call this function? To call this we need to assign it to a variable like this: a = lambda x, y: x + y Now, we can call it like we call a normal function. > a(5,6) > 11 We can call the function 'a' anytime we want in code. Also, Anonymous function are nothing but lambda function. When we don't assign lambda function to a variable they are called anonymous. _________________________________ I shortened the wording of the answer here, pls let me if you don't understand anything.
8th Jul 2022, 4:15 PM
Sandeep
Sandeep - avatar
+ 3
Gabriel Burchfield , i suppose you mean lambda functions. here are 3 links from the community section it covers lambda in detail, and also links that demonstrate the use of it: https://www.sololearn.com/learn/JUMP_LINK__&&__Python__&&__JUMP_LINK/2460/?ref=app https://www.sololearn.com/learn/Python/2461/?ref=app https://www.sololearn.com/learn/Python/2466/?ref=app
8th Jul 2022, 2:03 PM
Lothar
Lothar - avatar
+ 2
I can help you in remembering the syntax. To understand lambda, you need to first know function (I am assuming you know how to define function) let's define a simple function that add two values, the name of the function is lambda (i deliberately did that): def lambda(x, y): return x + y Now, the goal is to convert this to lambda function. Lambda function was introduced to make the code shorter for simple tasks. To make this shorter, remove the 'def' keyword from above function defination and move everything on one line. It becomes: > lambda(x, y): return x + y Still, seems to be hard to write. Remove the 'return keyword from above shorter version: > lambda(x, y): x + y Hmm, let's remove the parentheses () also: > lambda x, y: x + y and that is your lambda expression, just a short way too write function. Now, this is good for remembering the syntax. Note here i deliberately chose name of first function as lambda. lambda is special keyword (like def) and short func can be defined only using lambda
8th Jul 2022, 4:06 PM
Sandeep
Sandeep - avatar
+ 1
Thank you! Lothar
8th Jul 2022, 3:05 PM
Gabriel Burchfield