Python anonymous functions

Source: Internet
Author: User

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

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.