Use of Lambda function in Python

This post is about Lambda which remain one of the most confusing topic for beginners. After reading couple of articles, here I’m sharing gist of them.
Lambda is used to create function like def() but it returns the function instead of assigning name to it. This is the reason it is also called anonymous function.

what-is-lambda
Lambda function enable to add functionality where we don’t need to call function more than once.
For more understanding, have a look at the difference of lambda from function.

how to use lambda

 

Taking another example of for loop with and without Lambda,

Without Lambda

example-of-lambda-in-python-for-loop

With Lambda, we can achieve the same result in one line.

example-of-lambda-in-python-for-loop-

Few more examples here: http://p-nand-q.com/python/lambda.html