In a for-loop I attempt to overwrite string-type variables.
item1 = "Item 1"
item2 = "Item 2"
for item in [item1, item2]:
if item == "Item 2":
item = "Item 1"
print (item1, item2)
The print that results says "Item 1 Item 2"
. It should say "Item 1 Item 1"
I also tried item = item.replace("Item 2","Item 1")
. Same result.
What prevents "Item 2"
from getting replaced?
Update:
Similar to Changing iteration variable inside for loop in Python but with strings, not integers.
I have a much longer list of variables to validate and overwrite, so a for-loop that just uses the current item for reassignment would be ideal (as opposed to item2 = "Item 1")