Python Forum
What is the meaning of mutable data type?
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
What is the meaning of mutable data type?
#4
The first time I ran across immutable strings I found it very confusing, but that was coming from a world were there was no garbage collection unless I did it myself. In C you create/protect/cherish your data structures because they are the foundation of your program. In Python they are tossed away like a used tissue.

But I have to say there are some nice things about immutable strings. I don't have to worry about a string changing value in python. In C, if I kept a string I usually made a copy to protect against the string changing outside the scope of my module. Python does that automatically, and only if I need a copy. If the string I am passed never changes it can be used all over the place and still be the only string. No copies unless needed and then the copies are made automatically. How cool is that!

To a lesser extent I like tuples for the same reason. If I put something in a tuple I don't have to worry about it changing. If I want something that acts more like a C array (a shared resource that can be modified and all users have access to the same modified value) I just use a list (or a python array).
Reply


Messages In This Thread
What is the meaning of mutable data type? - by qliu - Apr-17-2020, 02:51 PM
RE: What is the meaning of mutable data type? - by deanhystad - Apr-17-2020, 07:20 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  using mutable in function defintion as optional paramter akbarza 8 315 6 hours ago
Last Post: snippsat
  Unable to understand the meaning of the line of code. jahuja73 0 314 Jan-23-2024, 05:09 AM
Last Post: jahuja73
  mutable argument in function definition akbarza 1 494 Dec-15-2023, 02:00 PM
Last Post: deanhystad
  Csv writer meaning of quoting mg24 2 1,164 Oct-01-2022, 02:16 PM
Last Post: Gribouillis
  mutable values to string items? fozz 15 2,871 Aug-30-2022, 07:20 PM
Last Post: deanhystad
  meaning of -> syntax in function definition DrakeSoft 5 1,977 Apr-09-2022, 07:45 AM
Last Post: DrakeSoft
  Operator meaning explanation Sherine 3 2,053 Jul-31-2021, 11:05 AM
Last Post: Sherine
  blank graph with matplotlib from a csv file / data type issue arsentievalex 0 1,960 Apr-06-2021, 10:08 AM
Last Post: arsentievalex
  What type of *data* is the name of a list/tuple/dict, etc? alloydog 9 4,402 Jan-30-2021, 07:11 AM
Last Post: alloydog
  "'DataFrame' objects are mutable, thus they cannot be hashed" Mark17 1 6,841 Dec-25-2020, 02:31 AM
Last Post: tinh

Forum Jump:

User Panel Messages

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