python update outer passed value from within a for loop
问题 My question is a slight variation of How do I pass a variable by reference? - however I still can't find a simple solution to the problem illustrated below: how can I alter the values of the outer string variables from within a for-loop? str1 = 'before' str2 = 'before' for i in str1,str2: print "%s" % (i) i = "after" for i in str1,str2: print "%s" % (i) Thanks for the helpful responses below however they haven't really helped with my specific problem, the code below is less generic but better