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)

Billboard image

Create up to 10 Postgres Databases on Neon's free plan.

If you're starting a new project, Neon has got your databases covered. No credit cards. No trials. No getting in your way.

Try Neon for Free →

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay