Python---higher-order functions as parameters

Source: Internet
Author: User
With the function as a parameter in section 2.1, we talk about the concept of higher-order functions and write a simple high-order function: def Add (x, Y, f):     return f (x) + f (Y) if incoming ABS is the value of the parameter F: Add (-5, 9, ABS) according to the definition of the function, the code that the function executes is actually: ABS (-5) + ABS (9) Because parameter x, Y, and F can all be passed in arbitrarily, if f passes into other functions, it can get different return values. The task takes advantage of the Add (x,y,f) function, which calculates:import  mathdef  Add (x,    y, f):return f (x) + f (y)print Add (9, MATH.SQRT)

Python---higher-order functions as parameters

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.