Python Forum
Keeping a value the same despite changing the variable it was equated to
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Keeping a value the same despite changing the variable it was equated to
#1
I'm beginning to learn Python and I've come across a problem that is foreign to me as a past Lua programmer. I've noticed that after appending a variable to a list, if that variable changes value so does the value in the list as well, even though the list was never directly redefined.
Here's what I mean,

currentPath = ["EWR", "JFK", "SFO"]
completedPaths = []

completedPaths.append(currentPath)
print(completedPaths)

currentPath.clear()
print(completedPaths)
Output:
["EWR", "JFK", "SFO"] [[]]
This confuses me because in Lua the list in completedPaths would stay the same until directly redefined, even if the variable it was once equated to has changed. How would I solidify the list inside of completedPaths while also changing the currentPath variable to input more values later on?
Reply


Messages In This Thread
Keeping a value the same despite changing the variable it was equated to - by TheTypicalDoge - Mar-13-2022, 08:25 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Keeping up with IDEs and Virtual Environments... bytecrunch 7 2,816 Sep-05-2022, 08:04 PM
Last Post: snippsat
  Problem keeping the window up benlyboy 11 4,371 Jan-24-2020, 02:12 AM
Last Post: tamilselvisubbiah
  Changing a variable's name on each iteration of a loop rix 6 85,920 Jan-03-2020, 07:06 AM
Last Post: perfringo
  merging lists, dedup and keeping order, in older pythons Skaperen 3 3,270 Oct-19-2018, 01:30 AM
Last Post: ODIS
  Keeping Intersection of an Image Only Anysja 4 3,071 Aug-15-2018, 09:47 PM
Last Post: Anysja
  help with keeping score W3BL3Y 2 6,420 Apr-29-2018, 01:12 PM
Last Post: W3BL3Y
  int(variable) not changing variable to an integer StoopidChicken 2 3,047 Jan-11-2018, 10:30 AM
Last Post: StoopidChicken
  Questions on variable changing between files. Sello 12 7,332 Apr-25-2017, 04:59 AM
Last Post: wavic
  changing variable outside of a function tkj80 8 7,453 Jan-05-2017, 03:52 AM
Last Post: tkj80

Forum Jump:

User Panel Messages

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