0

i started to learn python and i want to create variables with loop. I wrote the code below but I couldn't reach what I wanted.

for i in range(50):
    var["i%d"% i]=IntVar()

i want something like that:

var1 = IntVar()
var2 = IntVar()
var3 = IntVar()
     .
     .

How can i do that, thanks for help.

  • looks like you need this: https://developers.google.com/edu/python/lists – Rafael Jul 03 '21 at 11:51
  • 1
    "i started to learn python and i want to create variables with loop ... " The next step in your learning is to suppress that desire. Use a proper data structure such as a list or dictionary instead. – John Coleman Jul 03 '21 at 11:57
  • you don't need to declare variables in python. but if you are interested in typing ``` from typing import List int_list = List[int] ``` – Joshua Cabanas Jul 03 '21 at 12:08

1 Answers1

0

You cannot actually create a variable with a different name this way. You can add values to a list though, and gather the values later on, put hem inside variables... Why do you need to create so many variables ? Maybe you can skip that step and use a list. Try working this way around your problem.

Nephty
  • 140
  • 1
  • 7