DEV Community

zehra hindioğlu
zehra hindioğlu

Posted on

Python Lambda Function

Functions that we defined anonymously and one-liner in Python are called lambda functions. Accept multiple parameters, performs a single action. It provides a cleaner structure by writing less code for simple mathematical or conversion operations.

Image description

In the lambda function (:) the parts before this sign are parameters. The parts after this sign are the operations to be performed.

Let's compare “def” and “lambda” with an example:

Image description

def and lambda perform the same function. In other words, it takes the square of the entered number. But look at the cleanliness of the lambda written in a single line.

Top comments (0)