I am wondering, if it is possible to create variables and name the using strings and other variables on Python. It would really help me on sth I’m making.
For example i want to create 10 variables:
var0
var1
var2
...
I have tried doing it with the “for” loop like this:
for i in range(10):
'var'+str(i) = 0
but it gives me an error. Please help!
Any help would be much appreciated.
You don’t want to be using “variable variables”. You want to use a dictionary:
Now you can access each element like this
var[6](and you’re not limited to integers as dictionary keys, either:var["yay!"] = "Great!").Of course, for the special case of a range of 0 to 9, you can also simply use a list: