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 Docusign

🛠️ Bring your solution into Docusign. Reach over 1.6M customers.

Docusign is now extensible. Overcome challenges with disconnected products and inaccessible data by bringing your solutions into Docusign and publishing to 1.6M customers in the App Center.

Learn more

Top comments (0)

A Workflow Copilot. Tailored to You.

Pieces.app image

Our desktop app, with its intelligent copilot, streamlines coding by generating snippets, extracting code from screenshots, and accelerating problem-solving.

Read the docs