为什么python方法存储在不同的地址?

gku*_*erz 3 python methods attributes

<built-in method sort of list object at 0x10794e488>
>>> [].sort
<built-in method sort of list object at 0x10794e6c8>
>>> [].sort
<built-in method sort of list object at 0x10794e488>
>>> [].sort
<built-in method sort of list object at 0x10794e6c8>
Run Code Online (Sandbox Code Playgroud)

为什么python方法存储在两个不同的地址中?

Ada*_*Er8 6

它不是方法的地址,而是对象的地址。

您每次创建一个新的列表对象。

如果将其保存在变量中,您将获得相同的地址(并且对于所有方法...)

>>> a = []
>>> a.sort
<built-in method sort of list object at 0x7f78138fa688>
>>> a.sort
<built-in method sort of list object at 0x7f78138fa688>
>>> a.count
<built-in method sort of list object at 0x7f78138fa688>
>>> a.index
<built-in method sort of list object at 0x7f78138fa688>
>>> 
Run Code Online (Sandbox Code Playgroud)