Python Principles
Python Q&A

How do you create a variable number of variables?


You should probably use a dictionary to solve your problem. It lets you create a mapping between keys and values, where the keys are a way to represent the "variables" you want to create a variable number of.

For examples:

my_vars = {}
for i in range(10):
    var_name = "var%d" % i
    my_vars[var_name] = i


This is equivalent to creating var0 = 0, var1 = 1, and so on.