Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Value by reference issue
#5
Numbers and strings are immutable objects in Python. Since, by definition, an immutable object cannot change, it doesn't make any sense to "copy" an immutable object. The object's "value" will always be the same and any copy is just wasted memory.

Variables in Python are entries in a dictionary. They are not "memory" that can be filled with different values. The only way to change a variable is through assignment (val = 5).

What is it you are trying to do? I don't understand what you mean by this:
Quote:I've run across an issue with trying to copy an int argument for later use in the program. I realized the int that was copied is changing the value of the original argument

I think you should post your code and describe the problem you are having. The example you post is not helping me understand your real problem.
Reply


Messages In This Thread
Value by reference issue - by javaben - Jul-30-2021, 10:40 PM
RE: Value by reference issue - by bowlofred - Jul-30-2021, 11:32 PM
RE: Value by reference issue - by javaben - Jul-30-2021, 11:59 PM
RE: Value by reference issue - by javaben - Jul-31-2021, 02:36 AM
RE: Value by reference issue - by bowlofred - Jul-31-2021, 12:22 AM
RE: Value by reference issue - by deanhystad - Jul-31-2021, 12:24 AM
RE: Value by reference issue - by deanhystad - Jul-31-2021, 04:47 AM
RE: Value by reference issue - by javaben - Jul-31-2021, 04:48 AM
RE: Value by reference issue - by deanhystad - Jul-31-2021, 04:59 AM
RE: Value by reference issue - by javaben - Jul-31-2021, 12:55 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Pass by object reference when does it behave like pass by value or reference? mczarnek 2 2,581 Sep-07-2020, 08:02 AM
Last Post: perfringo

Forum Jump:

User Panel Messages

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