Sololearn: Learn to Code
New course! Every coder should learn Generative AI!
Try a free lesson
+ 5
Lambdas are like "anonymous", one-time, one-purpose methods, which do not require proper defining. If you don't need to use a function/method multiple times in your code, you can use lambda. The syntax is awfully simple: print((lambda x: x**2)(10)) Anonymous lambda function taking x as argument, returns the square of x - and you give it 10 as argument. The output result is... . . . . . . . . . . . . 100, of course :)
19th Jul 2017, 7:04 AM
Kuba Siekierzyński
Kuba Siekierzyński - avatar