+ 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.
5 Respuestas
+ 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
+ 9
Thanks Lisa
+ 9
Thanks Ishan Shah great explanation
+ 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.
+ 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.