0

I want to make a variable that can be changed iterably through for loops, as in:

for i in range(15):
  var + i = 12

so that when it is finished, there will be 15 variables that has the number 12. I've done this through code.org (I'm taking computer science) and I want to know if this is possible through python.

1 Answers1

1

Like that?

g = globals()
for i in range(15):
    g[f'var{i}'] = 12

It can be useful for practise, to understand how variables storing. In real projects you should use some sort of collections. Usually list or dict.

Alpensin
  • 191
  • 1
  • 10