Lambda and Pythonlambda functions in Python
When I was reading a book today, I saw such a statement:
if isinstance(value,int) or isinstance(value,float): split_function=lambda row:row[column]>=value
Lambda is not clear, so I read the Python documentation, which explains the following:
-
Lambda
-
An anonymous inline function consisting of a single
ExpressionWhich is evaluated when the function is called. The syntax to create a lambda function is Lambda [arguments]: expression
-
Lambda functions are also called anonymous functions, that is, they do not have a specific name, but the method created with def has a name.
-
Lambda allows users to quickly define
Single Row FunctionOf course, you can also complete the function according to the typical function definition. Lambda aims to simplify the process of defining and using functions.
-
For example:
log2=lambda x:log(x)/log(2)
A base-2 logarithm function is defined. In this example, there is a parameter. In another case, there is no parameter:
>>>bar=lambda :'this is a bar'>>>print barthis is a bar