Re: Two aces up Python's sleeve

Liste des GroupesRevenir à cl python 
Sujet : Re: Two aces up Python's sleeve
De : PythonList (at) *nospam* DancesWithMice.info (dn)
Groupes : comp.lang.python
Date : 08. Nov 2024, 02:07:48
Autres entêtes
Organisation : DWM
Message-ID : <mailman.87.1731024481.4695.python-list@python.org>
References : 1 2 3 4 5 6
User-Agent : Mozilla Thunderbird
On 8/11/24 11:15, Greg Ewing via Python-list wrote:
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.
Haven't seen the OP. Is the Newsgroup link forwarding to the email-list correctly?
Integer interning is indeed valid for -5 <= i <= 256
("it works on my machine"! see below)
 >>> a = 0; b = 0; c = 0; d = 0
 >>> while a is b:
...     print( a, b, end=" ", )
...     print( c, d, ) if c is d else print()
...     a += 1; b += 1; c -= 1; d -= 1
...
0 0 0 0
1 1 -1 -1
2 2 -2 -2
3 3 -3 -3
4 4 -4 -4
5 5 -5 -5
6 6
7 7
8 8
9 9
...
254 254
255 255
256 256
 >>>
Be aware that this is implementation-dependent and not guaranteed to hold forever.
  dn  ~  python
Python 3.12.7 (main, Oct  1 2024, 00:00:00) [GCC 13.3.1 20240913 (Red Hat 13.3.1-3)] on linux
Type "help", "copyright", "credits" or "license" for more information.
See also https://docs.python.org/3/library/sys.html#sys.intern
Thus could decide what is interned for yourself:
a_string = sys.intern( str( 1000 ) )
--
Regards,
=dn

Date Sujet#  Auteur
6 Nov 24 * Two aces up Python's sleeve15Stefan Ram
6 Nov18:27 `* 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