在Python中,'<函数在...>'意思? [英] In Python, what does '<function at ...>' mean?

查看:606
本文介绍了在Python中,'<函数在...>'意思?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

> 的函数<是什么意思?例如:

What does <function at 'somewhere'> mean? Example:

>>> def main():
...     pass
...
>>> main
<function main at 0x7f95cf42f320>

也许可以通过 0x7f95cf42f320以某种方式访问​​它

And maybe there is a way to somehow access it using 0x7f95cf42f320?

推荐答案

您正在查看函数对象的默认表示形式。它提供了一个名称和一个唯一的ID,它在CPython 发生中是一个内存地址。

You are looking at the default representation of a function object. It provides you with a name and a unique id, which in CPython happens to be a memory address.

您无法使用地址访问它;内存地址仅用于帮助您区分函数对象。

You cannot access it using the address; the memory address is only used to help you distinguish between function objects.

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

In other words, if you have two function objects which were originally named main, you can still see that they are different:

>>> def main(): pass
... 
>>> foo = main
>>> def main(): pass
... 
>>> foo is main
False
>>> foo
<function main at 0x1004ca500>
>>> main
<function main at 0x1005778c0>

这篇关于在Python中,'&lt;函数在...&gt;'意思?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆