+ 14

Why should we use lambda functions instead of normal def functions?

Both lambda functions and normal functions are doing the same work. Then why should we introduce new lambda functions as already normal functions exist.

16th May 2020, 2:27 AM
Puthur Harthik
5 odpowiedzi
+ 5
hello Puthur Harthik Lambda functions are used when you need a function for a short period of time A lambda function can take any number of arguments, but they contain only a single expression. An expression is a piece of code executed by the lambda function, which may or may not return any value. Lambda functions can be used to return function objects. Syntactically, lambda functions are restricted to only a single expression. i hope this will help to you
18th May 2020, 6:18 AM
Ishan Shah
Ishan Shah - avatar
+ 9
Thanks Lisa
16th May 2020, 7:04 AM
Puthur Harthik
+ 9
Thanks Ishan Shah great explanation
18th May 2020, 6:19 AM
Puthur Harthik
+ 5
lambda is useful for short and simple functions as they are usually shorter than normal def-functions. For more complicated stuff, lambda is not recommended and hard to read. It good to understand lambda functions when reading someone else's code but if you don't like them, there so need to use them yourself.
16th May 2020, 6:55 AM
Lisa
Lisa - avatar
+ 2
Puthur Harthik If you have to waste many lines on a simple function. Then it would be easier to make the function in a single line.
21st May 2020, 12:42 PM
Ketan Pal
Ketan Pal - avatar