Lambda and Pythonlambda functions in Python

Source: Internet
Author: User

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

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.