Python Forum
About integer objects vs integer values
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
About integer objects vs integer values
#9
Nwb Wrote:But in Python, assigning to an integer variable would mean allocating new memory for a new object
This is not true. Assigning to an integer variable simply increases the reference count of an existing (python) integer instance.

Your reasoning works for certain operations such as augmented assignments
x += 1
In python this augmented assignment creates a new PyInt_Object because the intitial object may have other references pointing at it. Variables, better called names in python, are only references to shared objects.

The design of python is excellent, which explains the success of the language. The best thing to do if you want to understand it is to write a few C extension modules using the C api.
Reply


Messages In This Thread
About integer objects vs integer values - by Nwb - Apr-25-2019, 04:55 AM
RE: About integer objects vs integer values - by Gribouillis - Apr-27-2019, 04:31 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Does the integer implementation matter? ichabod801 2 1,844 Oct-22-2019, 03:26 PM
Last Post: snippsat
  integer bases Skaperen 7 4,718 Nov-24-2017, 09:46 AM
Last Post: heiner55
  multiplying integer to decimal ArnabRoyBatman 8 12,685 Jun-20-2017, 04:49 PM
Last Post: DeaD_EyE

Forum Jump:

User Panel Messages

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