May-28-2020, 11:08 AM
I want to create and assign a value to a variables in a for loop and name the variable in the loop. This works as intended. Afterwards, I would like to print the variables something like:
var0
var1
var2
Whereas I want output corresponding to this:
a = 3 source=(0.1, 0.2, 0.3) for n in range (a): exec("var"+str(n)+" = source[n]") print('var'+str(n))However, I end up with:
var0
var1
var2
Whereas I want output corresponding to this:
print(var0) print(var1) print(var2)How do I change the code accordingly?