Python---higher-order functions

Source: Internet
Author: User

The #  higher order function #  variable can point to the function #  the Python built-in absolute value of the function abs () For example, call the function with the following code print (ABS ( -10)) #  write abs#  output as:< Built-in function abs>print (ABS) # abs (-10) is a function call, and ABS is the function itself #  to get the result of a function call, we can assign the result to the variable X  = abs ( -10) print (x) #  assigns the function itself to the variable f = absprint (f) The #  function itself can also assign a value to the variable, that is, the variable can point to the function #  If a variable points to a function, the function can be called by a variable f = absprint (f ( -10)) # -------------------------------------------- ----------------#  function name is also a variable #  function name is actually a variable that points to the function #  for abs () This function, it is possible to think of ABS as a variable, it points to a function that can calculate the absolute value #  If the ABS points to other objects in the call, the system will error:    typeerror:  ' int '  object is not callable # abs = 10# print (ABS ( -10)) #  because the ABS function is actually defined in the Import builtins module, So to modify the point of the ABS variable is also effective in other modules, to use import builtins; builtins.abs=10# ------------------------------------ ------------------------#  incoming function #  since the variable can point to a function, the function's arguments can receive the variable, then one function can receive another function as a parameter, which is called the higher order function #  One of the simplest high-order functions Def add (X,&NBSP;Y,&NBSP;F): &Nbsp;   return f (x)  + f (y) print (' Add ( -5, 6, abs): ',  add ( -5,  6, abs)) #  write higher-order functions, that is, to allow the function's parameters to receive other functions #  the function as a parameter, such a function is called higher-order function, functional programming refers to this highly abstract programming paradigm


Python---higher-order functions

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.