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
Python Lambda with underscore
The ‘_’ is the variable name. This variable name is usually a name for an ignored variable.
This function can be used when we want to get a specific output for every input.
- How to pass argument to an Exception in Python?
- Passing function as an argument in Python
- Python lambda
- Pass list as command line argument in Python
- Overuse of lambda expressions in Python
- Python | sympy.Lambda() method
- Lambda and filter in Python Examples
- Nested Lambda Function in Python
- Command-Line Option and Argument Parsing using argparse in Python
- Difference between List comprehension and Lambda in Python
- Map function and Lambda expression in Python to replace characters
- Python Program to Sort the list according to the column using lambda
- Python lambda (Anonymous Functions) | filter, map, reduce
- Python | Find fibonacci series upto n using lambda
- Lambda expression in Python to rearrange positive and negative numbers
- Intersection of two arrays in Python ( Lambda expression and filter function )
- Ways to sort list of dictionaries by values in Python - Using lambda function
- Python | Find the Number Occurring Odd Number of Times using Lambda expression and reduce function
- Underscore (_) in Python
- Reusable piece of python functionality for wrapping arbitrary blocks of code : Python Context Managers
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.