Anonymous Functions:
- In Python, an anonymous function is a function that is defined without a name.
- While normal functions are defined using the def keyword, in Python anonymous functions are defined using the lambda keyword.
- Hence, anonymous functions are also called as lambda functions.
Use of lambda or anonymous function:
- Lambda function is mostly used for creating small and one-time anonymous functions. That means, Lambda function can take any number of arguments and must return one value in the form of an expression
- Lambda functions are mainly used in combination with the functions like filter(), map() and reduce().
Syntax:
Example program:
Output:
No comments:
Post a Comment