Python Forum
Variables as labels vs fixed storage location
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Variables as labels vs fixed storage location
#2
Well, you're also using small ints.  Those, in particular, will have the same id... but only on cpython.  Any other implementation of python (IronPython, jython, pypy, etc) might not work that way.  And that's only because of an optimization the cpython compiler uses (it assumes small ints are used fairly frequently, so it just caches them and shares them all over the place).

If you try the same thing with strings, it doesn't do that anymore...

# 50 is the same...
>>> id(50)
1426349088
>>> id(50)
1426349088
>>> id(50)
1426349088
>>> id(50)
1426349088

# but "50" is not the same...
>>> id("50")
31633984
>>> id("50")
31635328
>>> id("50")
31635296
>>> id("50")
31634464
>>> id("50")
31633920
Reply


Messages In This Thread
RE: Variables as labels vs fixed storage location - by nilamo - Sep-21-2017, 10:01 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  uploading files from a ubuntu local directory to Minio storage container dchilambo 0 600 Dec-22-2023, 07:17 AM
Last Post: dchilambo
  Upload Files to Azure Storage Container phillyfa 6 965 Dec-22-2023, 06:11 AM
Last Post: Pedroski55
  How to do "fixed size" (wrapping) math in Python? AlexanderWulf 13 2,218 Jul-19-2023, 04:13 PM
Last Post: deanhystad
  Fixed colum width for rowLabels i Matplotlib pandabay 0 506 Jun-10-2023, 03:40 PM
Last Post: pandabay
  Encrypt and decrypt in python using own fixed key SriRajesh 3 5,423 Feb-20-2022, 01:18 PM
Last Post: dboxall123
  Play fixed frequency sound in python 3 jpezz 2 2,913 Feb-07-2021, 08:21 PM
Last Post: jpezz
  Referencing a fixed cell Mark17 2 2,169 Dec-17-2020, 07:14 PM
Last Post: Mark17
  Secure App Data Storage for Kivy Android App JonPC 1 2,527 Nov-08-2019, 03:42 PM
Last Post: luke
  Real time graph of the temperatures and storage linkxxx 3 2,805 Aug-29-2019, 09:44 AM
Last Post: linkxxx
  Show real time temperature and storage with Python linkxxx 4 2,881 Aug-28-2019, 02:06 PM
Last Post: linkxxx

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020