[英]Why python methods are stored in different addresses?
<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>
為什么python方法存儲在兩個不同的地址中?
它不是方法的地址,而是對象的地址。
您每次都創建一個新的列表對象。
如果將其保存在變量中,您將獲得相同的地址(並且對於所有方法......)
>>> 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>
>>>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.