Python Lambda Functions
Python Lambda function is known as the anonymous function that is defined without a name. Python allows us to not declare the function in the standard manner, i.e., by using the def keyword. Rather, the anonymous functions are declared by using the lambda keyword. However, Lambda functions can accept any number of arguments, but they can return only one value in the form of expression.
The anonymous function contains a small piece of code. It simulates inline functions of C and C++, but it is not exactly an inline function.
The syntax to define an anonymous function is given below.
It can accept any number of arguments and has only one expression. It is useful when the function objects are required.
Consider the following example of the lambda function.
<function <lambda> at 0x0000019E285D16A8> sum = 30
In the above example, we have defined the lambda a: a+10 anonymous function where a is an argument and a+10 is an expression. The given expression gets evaluated and returned the result. The above lambda function is same as the normal function.
Multiple arguments to Lambda function
JavaTpoint offers too many high quality services. Mail us on [email protected], to get more information about given services.
JavaTpoint offers college campus training on Core Java, Advance Java, .Net, Android, Hadoop, PHP, Web Technology and Python. Please mail your requirement at [email protected]
Duration: 1 week to 2 week