Consider the following:
var1 = 0
var2 = 1
var3 = 2
var4 = 3
If I were to add another variable, I could manually add it:
var1 = 0
...
var5 = 4
Note that the values assigned to the variables are numbers increasing, in this case, by one. I would like to change by how much too, say by three:
var1 = 0
var2 = 3
var3 = 6
var4 = 9
var5 = 12
The closest thing I could find in this regards was the following, which is found in this answer:
for j in range(1,10,1):
exec('var_%d = j'%j)
range()
allows me to set the starting and ending point of the values by a given step.exec()
allows me to execute the statement.
The author of the answer warns against the usage of this, but I fail to see why. I suppose this is because of exec()
. However, I don't see another way around this, so I asked this question.