Re: Two aces up Python's sleeve

Liste des GroupesRevenir à cl python 
Sujet : Re: Two aces up Python's sleeve
De : janburse (at) *nospam* fastmail.fm (Mild Shock)
Groupes : comp.lang.python
Date : 08. Nov 2024, 02:29:48
Autres entêtes
Message-ID : <vgjm1s$ki9n$2@solani.org>
References : 1 2 3 4 5 6
User-Agent : Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:91.0) Gecko/20100101 Firefox/91.0 SeaMonkey/2.53.19
For example this article:
https://www.codementor.io/@arpitbhayani/python-caches-integers-16jih595jk
about the integer singletons claims:
 >>> x, y = 257, 257
 >>> id(x) == id(y)
False
But on Windows my recent CPython doesn't do that:
Python 3.14.0a1 (tags/v3.14.0a1:8cdaca8, Oct 15 2024, 20:08:21)
 >>> x, y = 257, 257
 >>> id(x) == id(y)
True
Mild Shock schrieb:
Hi,
 In Java its possible to work this way
with the Integer datatype, just call
Integer.valueOf().
 I am not sure whether CPython does the
same. Because it shows me the same behaviour
for small integers that are more than
 only in the range -128 to 128. You can try yourself:
 Python 3.14.0a1 (tags/v3.14.0a1:8cdaca8, Oct 15 2024, 20:08:21)
 >>> x,y = 10**10, 10**9*10
 >>> id(x) == id(y)
True
 Maybe the idea that objects have an address
that can be accessed via id() has been abandoned.
This is already seen in PyPy. So maybe we
 are falsly assuming that id() gives na object address.
 Greg Ewing schrieb:
On 8/11/24 3:04 am, Mild Shock wrote:
This only works for small integers. I guess
this is because tagged pointers are used
nowadays ?
>
No, it's because integers in a certain small range are cached. Not sure what the actual range is nowadays, it used to be something like -5 to 256 I think.
>
BTW you have to be careful testing this, because the compiler sometimes does constant folding, so you need to be sure it's actually computing the numbers at run time.
>
 

Date Sujet#  Auteur
6 Nov 24 * Two aces up Python's sleeve15Stefan Ram
6 Nov 24 `* Re: Two aces up Python's sleeve14Mild Shock
7 Nov09:25  `* Re: Two aces up Python's sleeve13Annada Behera
7 Nov13:03   +- Re: Two aces up Python's sleeve1Stefan Ram
7 Nov16:04   +* Re: Two aces up Python's sleeve6Mild Shock
8 Nov00:15   i`* Re: Two aces up Python's sleeve5Greg Ewing
8 Nov02:07   i +- Re: Two aces up Python's sleeve1dn
8 Nov02:25   i `* Re: Two aces up Python's sleeve3Mild Shock
8 Nov02:29   i  `* Re: Two aces up Python's sleeve2Mild Shock
8 Nov02:47   i   `- Re: Two aces up Python's sleeve1Mild Shock
8 Nov03:10   `* Re: Two aces up Python's sleeve (Posting On Python-List Prohibited)5Lawrence D'Oliveiro
8 Nov03:40    `* Re: Two aces up Python's sleeve (Posting On Python-List Prohibited)4Mild Shock
8 Nov21:09     +* Re: Two aces up Python's sleeve (Posting On Python-List Prohibited)2dn
8 Nov21:49     i`- Re: Two aces up Python's sleeve (Posting On Python-List Prohibited)1Mild Shock
9 Nov00:00     `- Re: Two aces up Python's sleeve (Posting On Python-List Prohibited)1Thomas Passin

Haut de la page

Les messages affichés proviennent d'usenet.

NewsPortal