Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Are tuples immutable?
#7
(Jan-06-2019, 03:28 PM)ichabod801 Wrote:
(Jan-06-2019, 01:00 PM)python_user_n Wrote: By modifying an object / item in tuple I modify tuple itself.

I think this is your key misunderstanding. You are not modifying the tuple. The tuple in memory is completely unchanged. Glossing over implementation details, the tuple contained two things when created: an integer and a reference to (memory location of) a list. You changed the list by referencing it through the tuple. After that, the tuple is still the same. It contains the same integer, and the same memory location. What is at that memory location changed, but that did not involve any changes in what is stored in the tuple. It just looks like you did, because python shows you what is at the memory location instead of that memory location itself.

Thank you. But I understood that from the Python definition.
Where I disagree is in the case you transfer this object (a tuple) somewhere you can't just transfer the integer and reference. You must transfer the objects to which the tuple contain references. So your overall object size in this case depend on referenced objects, and not only tuple itself. If we modify them this will impact the size. And size is mutable and can be considerably different from initial object size.
That's how I see it.

Anyway thanks everyone for your time and answers. Cya in the next question ;)
Reply


Messages In This Thread
Are tuples immutable? - by python_user_n - Jan-06-2019, 01:00 PM
RE: Are tuples immutable? - by perfringo - Jan-06-2019, 01:53 PM
RE: Are tuples immutable? - by buran - Jan-06-2019, 02:27 PM
RE: Are tuples immutable? - by python_user_n - Jan-06-2019, 02:41 PM
RE: Are tuples immutable? - by buran - Jan-06-2019, 03:06 PM
RE: Are tuples immutable? - by ichabod801 - Jan-06-2019, 03:28 PM
RE: Are tuples immutable? - by python_user_n - Jan-06-2019, 04:24 PM
RE: Are tuples immutable? - by ichabod801 - Jan-06-2019, 04:39 PM
RE: Are tuples immutable? - by micseydel - Jan-06-2019, 04:46 PM
RE: Are tuples immutable? - by python_user_n - Jan-06-2019, 05:21 PM
RE: Are tuples immutable? - by perfringo - Jan-07-2019, 08:04 AM
RE: Are tuples immutable? - by python_user_n - Jan-07-2019, 08:08 AM
RE: Are tuples immutable? - by buran - Jan-07-2019, 11:12 AM
RE: Are tuples immutable? - by python_user_n - Jan-07-2019, 01:26 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  immutable types Skaperen 2 2,111 Jul-09-2021, 01:00 AM
Last Post: Skaperen

Forum Jump:

User Panel Messages

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