Lambda or Functions defined? | Sololearn: Learn to code for FREE!
Neuer Kurs! Jeder Programmierer sollte generative KI lernen!
Kostenlose Lektion ausprobieren
+ 1

Lambda or Functions defined?

Being just a beginner at programming, I want to ask a question. Well, I found the Lambda method very convenient so far but as it is mentioned here in this course 'There's rarely a good reason to use lambda than define a function', I was quite in doubt. Why is it so? And at high level programming, are the programmers encouraged to use lambda? Which one do they prefer in programming :lambda or function ?

2nd Apr 2017, 2:18 PM
Sailesh
Sailesh - avatar
2 Antworten
+ 7
Hi there! According to all the python rules and beauty, the codes should be as short as possible. So if it is possible to use lambda where you need it, just go on and use it. Simple is better than complex. Complex is better than complicated;) The reason why they say that you rarely might need lambdas is that really you won't usually need to define something definable in one line as a separate lambda (module). Since it is mostly just a one line declaration, probably there is a better way to do it. (Again simple is better than complex). But still this doesn't mean that lambdas are completely useless, there are still many possible applications of lambdas like with filters. So just use lambdas where possible instead of functions if you need but you rarely really would. I'm a beginner as well, so this is just my opinion. I might be wrong somewhere, so I'd like to hear from more experienced programmers
3rd Apr 2017, 3:06 AM
Dinmukhamed Mailibay
Dinmukhamed Mailibay - avatar
0
Thank you for the answer!👍
3rd Apr 2017, 4:44 AM
Sailesh
Sailesh - avatar