A lambda function is a small anonymous function.

A lambda function can take any number of arguments, but can only have one expression.

Let us see a quick example of a lambda expression being used to square a number:

 sqr = lambda x: x * x  
 sqr(10)  # 100

As you can see, we write the name of the lambda function on the left side of the equal sign which we can then use to pass arguments to the lambda function.

Let us assume that we want to find whether a number is positive, i.e., greater than 0.

To do that, we need to compare the parameter passed to the lambda function and see whether it is greater than 0:

 is_positive = lambda  x: x > 0

Now if we call that function with a negative number, we are going to get False as the answer:

 is_positive(-3)  # False

That’s it for this quick article.

I hope you find it useful.