Use lambda keywords to create small anonymous functions. This function is named after the standard procedure for declaring a function with DEF is omitted.
The syntax for a lambda function contains only one statement, as follows:
Lambda parameter 1, parameter 2,... : An expression
>>> sum =Lambdax,y:x+y>>>Print(SUM (10,20))30#Application One: Only certain functions can be completed in this case>>>defTest (A,B,FUNC): ... result=func (A, b) ...Print(Result) ...>>> Test (10,20,Lambdax,y:x+y)30#Application II: Advanced#Python is a dynamic language that can enter anonymous functions with specific functionality based on the user's needs>>>defTest (A,B,FUNC): ... result=func (A, b) ...Print(Result) ...>>> func_new = input ("Please enter an anonymous function:"Please enter an anonymous function:Lambdax,y:x-y>>> func_new =eval (func_new)>>> Test (10,20, Func_new)-10
Python anonymous functions