这个输出的具体名称是什么?

What is the specific name of this output?

我创建了一个名为 'function' 的函数,如下所示。

>>> def function():
        return 'hello world'

>>> function
<function function at 0x7fac99db3048> #this is the output

这个输出到底是什么?是具体的名字吗?它的意义? 我知道它提供了有关内存位置的信息。但我需要有关此输出的更多信息。

高阶函数return在returning函数中是否有相似的数据?

为了调用该函数,您需要用()调用它。如果没有它,您将看到 对存储在 0x7fac99db3048function 函数 的引用。您也可以将其存储在另一个变量中:

>>> my_new = function  # store function object in different variable

>>> function
<function function at 0x10502bc80>
#                      ^ memory address of my system

>>> my_new
<function function at 0x10502bc80>
#                      ^ same as above

>>> my_new()    # performs same task
'hello world'

让我们看看另一个名字不是function的函数显示的内容:

>>> def hello_world():
...     print 'hello world'
...
>>> hello_world
#          v   Name of function
<function hello_world at 0x105027758>
# ^ says object of type 'function'|^- memory address of function
# (for eg: for class says 'class')|

在 python 中,函数是一个对象,因此当您调用 function 它时,它 returns 您就是内存地址。高阶函数的行为方式相同。但是有一些区别:

def a():
    print("Hello, World!")

def b():
    return a

>>> a
<function a at 0x7f8bd15ce668>
>>> b
<function b at 0x7f8bd15ce6e0>

c = b

>>>c
<function b at 0x7f8bd15ce6e0>

c = b()
<function a at 0x7f8bd15ce668>

注意creturns在不同情况下的功能