python3--Higher order functions

Source: Internet
Author: User

Intro: The function parentheses represent the function that is called, without parentheses representing the function itself (the name of the letter)

For example:

# seek absolute value built-in function abs>>>abs ( -10)     # call Function #            return call result >> >abs     # function itself <built- in function abs>     # returns the function itself

Higher-order function definitions:

A variable can point to a function, a function can receive a variable, and a function may receive another function as a parameter, which is called a higher order function.

n = 1def func1 (x, y):    return x+ydef FUNC2: return    XF = Func2 #变量指向函数本身 instead of   calling function f (n)   #函数接收变量, At this point F () is equivalent to Func2 () F (func1 ())  #一个函数接收另一个函数作为参数print (f (func1 ())) #结果3 #func2 () is called the higher order function

The function name is also a variable, if you assign a value to the function name, then you cannot call the function at the back, so you must not do so.

>>> ABS = 10>>> ABS ( -10) Traceback (most recent)  :"<stdin>< /c8>" in <module>'int' is not callable

Summarize:

A higher-order function is required only if one of the following conditions is true:

1. One function receives another or more functions as arguments

2. Function return returns another function itself

1 def f (x): 2       return abs,x   # returns the ABS function name, which is the return ABS function itself 34#F () is also a higher order function

python3--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.