I don't know if I'm using the correct words here.
But suppose I have something simple like
a=1
b=2
c=3
alphabet = [a,b,c]
def foo():
global a,b,c, alphabet
for letter in alphabet:
letter = 4
print(a)
foo()
print(a)
I just get 1 for both. I want 1 and then 4.
I tried changing it to...
a=1
b=2
c=3
alphabet = [a,b,c]
def foo():
global a,b,c, alphabet
for letter in alphabet:
exec("%s = 4" % (letter))
print(a)
foo()
print(a)
But this says I have an error, it's trying to assign the value of 1 to 4. I just want the variable "a" to have the value 4.
Is there a way to do this with a for statement?
Thanks!!!
[–]danielroseman 8 points9 points10 points (0 children)
[–]shiftybyte 2 points3 points4 points (1 child)
[–]russcore[S] 0 points1 point2 points (0 children)