Python Forum
Non-mutability of integer-valued variables.
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Non-mutability of integer-valued variables.
#1
I’m reading a tutorial on mutability of lists. The gist of it is that when one list is set to be equal to another, they point to the same part of the computer’s memory, hence modifying one would also modify the other. This would not happen with integer-valued variables, as belows. Why is it so? When I type “cheese += 1”, what happens with respect to the reference stored in the variable, and the computer’s memory?

spam = 42
cheese = spam
cheese += 1
cheese 
43
spam
42
Reply


Messages In This Thread
Non-mutability of integer-valued variables. - by ensbana - Jul-19-2020, 03:51 PM

Forum Jump:

User Panel Messages

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