Skip to content Skip to sidebar Skip to footer

How To Declare Multiple Similar Variables In Python?

How can I declare multiple (about 50) variables that count from slider1 to slider50 ? Is there an efficient way, like looping with for? slider1 = models.IntegerField(widget=widgets

Solution 1:

I would suggest using a Dictionary for this task:

d = {}

for x in range(1,10):
        d["slider{0}".format(x)]= models.IntegerField(widget=widgets.Slider, default=50, label="")

Post a Comment for "How To Declare Multiple Similar Variables In Python?"