Lambda

Lambda is another way of creating functions. There’s nothing intimidating about it, you’re already familiar with functions. The difference is lambda defines functions inline.

There’s nothing you can do with lambda that you can’t do with a normal Python function. Lambda functions work well on collections like lists.

Related course: Complete Python Bootcamp: Go from zero to hero in Python

Lambda function

Let’s start with a normal function and then create the lambda variant of it.
If we have a function like:

we can replace it with:

You could also do:

or combine it with map to apply the lambda function to each element:

 

Previous Post
Next Post

Leave a Reply

Your email address will not be published. Required fields are marked *