Why should we use lambda functions instead of normal def functions? | SoloLearn: Learn to code for FREE!

+9

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/16/2020 2:27:47 AM

Puthur Harthik

5 Answers

New Answer

+4

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

+8

Thanks Lisa

+8

Thanks Ishan Shah great explanation

+3

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.

0

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.