DEV Community

Divyanshu Shekhar
Divyanshu Shekhar

Posted on

1

Python Lambda Function

Python Lambda Function

Normally while defining a function in python we use the def keyword but when an anonymous function is declared we use the lambda keyword. These functions have no name.

And thus called the anonymous function.

Python Lambda Function Syntax

lambda arguments: expression
Enter fullscreen mode Exit fullscreen mode

The thing to keep in mind when using the lambda function is, there can be zero or multiple arguments separated by commas but only a single expression. Argument and expression in the lambda function are separated by a colon (:).

Expression in lambda functions is evaluated and returned. The whole lambda function returns a function object.

Learn Python list comprehension, an easy way to create a list in a single line.

The function object returned by the lambda function is stored in a variable. As the variable contains a function (Functions in python are also first-class citizens) it can be executed with the number of arguments passed in the lambda function.

Read the whole post Python Lambda Function from the original Post.

Image of Timescale

🚀 pgai Vectorizer: SQLAlchemy and LiteLLM Make Vector Search Simple

We built pgai Vectorizer to simplify embedding management for AI applications—without needing a separate database or complex infrastructure. Since launch, developers have created over 3,000 vectorizers on Timescale Cloud, with many more self-hosted.

Read full post →

Top comments (0)

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more