Python Lambda FunctionsPython 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. SyntaxIt 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. Example 1Output: <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. Example 2Multiple arguments to Lambda function |
原创文章,作者:ItWorker,如若转载,请注明出处:https://blog.ytso.com/263686.html