Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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>

Why python methods are stored in two different addresses?

like image 873
gkucmierz Avatar asked Jan 29 '26 19:01

gkucmierz


1 Answers

it's not the address of the method, but of the object.

you create a new list object each time.

if you save it in a variable, you'll get the same address (and for all methods...)

>>> 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>
>>> 
like image 164
Adam.Er8 Avatar answered Jan 31 '26 09:01

Adam.Er8