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.
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:
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)