在Python中,'<function at ...>'是什么意思?

Jad*_*una 5 python function repr memory-address

什么<function at 'somewhere'>意思?例:

>>> def main():
...     pass
...
>>> main
<function main at 0x7f95cf42f320>
Run Code Online (Sandbox Code Playgroud)

也许有办法以某种方式使用它0x7f95cf42f320

Mar*_*ers 10

您正在查看函数对象的默认表示.它为您提供了一个名称和一个唯一的ID,它在CPython中恰好是一个内存地址.

您无法使用该地址访问它; 内存地址仅用于帮助您区分功能对象.

换句话说,如果您有两个最初命名的函数对象main,您仍然可以看到它们是不同的:

>>> def main(): pass
... 
>>> foo = main
>>> def main(): pass
... 
>>> foo is main
False
>>> foo
<function main at 0x1004ca500>
>>> main
<function main at 0x1005778c0>
Run Code Online (Sandbox Code Playgroud)