0

To start off, I know almost nothing. What I want to do is have a variable with increasing numbers, like this:

testvar1 = "something"

testvar2 = "something else"

I want to automate this , so every time i run this part of the code, it will create a new var with one number bigger then the last var. This is probably very stupid. I would be happy if some would care to explain it to me. /:

Edit: Found it

import time
variables = {}
counter = 0
while True :
    variables[counter] = counter
    print(variables[counter])
    counter = counter + 1
    time.sleep(2)

Sorry. It´s fascinating that you only find the answer after asking somewhere.

  • well i guess you can create a variable `a = int(input())` `b = a + 1` – P.hunter Dec 19 '17 at 17:50
  • Depending on what you are trying to achieve, it may be better to look into using [arrays](https://docs.python.org/3/library/array.html). [Here](http://www.thegeekstuff.com/2013/08/python-array) is another good list of examples. – Luke Hollenback Dec 19 '17 at 17:53
  • This feels like you need to do a little more research and then come back with a specific question that addresses what you really need to understand Perhaps this is an X-Y problem? https://meta.stackexchange.com/questions/66377/what-is-the-xy-problem –  Dec 19 '17 at 17:54
  • 1
    You don't want this. This is a very typical approach of someone who just started programming. But this is not good design. Rather, you should learn to use containers. In this case, it sounds like you want a Python `list` – juanpa.arrivillaga Dec 19 '17 at 18:09
  • [Why you don't want to dynamically create variables](http://stupidpythonideas.blogspot.ae/2013/05/why-you-dont-want-to-dynamically-create.html) – Zero Piraeus Dec 20 '17 at 02:02

0 Answers0