Open In App
Related Articles

Python Lambda with underscore as an argument

Improve Article
Save Article
Like Article

In Python, we use the lambda keyword to declare an anonymous function. Lambda function behaves in the same way as regular functions behave that are declared using the ‘def’ keyword. The following are some of the characteristics of Python lambda functions:

  • A lambda function can take more than one number of arguments, but they contain only a single expression.
  • Lambda functions used to return function objects.
  • Syntactically, lambda functions are restricted to only one single expression.

Note: For more information, refer Python lambda

Creating a Lambda Function

Lambda functions can be created using the lambda keyword. We use the given syntax to declare a lambda function:

lambda argument(s) : expression


remainder = lambda num: num % 2



Python Lambda with underscore

The ‘_’ is the variable name. This variable name is usually a name for an ignored variable.


l = lambda _: True

Output :


This function can be used when we want to get a specific output for every input.

Whether you're preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape, GeeksforGeeks Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we've already empowered, and we're here to do the same for you. Don't miss out - check it out now!

Last Updated : 22 Jun, 2020
Like Article
Save Article
Similar Reads
Complete Tutorials