0

I'd like to make something like this in Python 3:

x = 0
while x < 20:
    variable0 = 2
    x += 1

The variable's name should change with every loop: 1st loop variable0, 2nd loop variable1, 3rd loop variable2, ...

jonrsharpe
  • 115,751
  • 26
  • 228
  • 437

1 Answers1

0

I would use a dict for this.

my_dict = dict() 
for x in range(20):
    my_dict["thing" + str(x)] = 2

for k, v in my_dict.items():
    print("{0} : {1}".format(k, v)) 
Michael Murphy
  • 1,921
  • 2
  • 18
  • 21