I am trying to make a program that makes a new variable multiple times in a function: my pseudo code:
increment = 1
"g" + increment = variable
increment = increment + 1
I am trying to make a program that makes a new variable multiple times in a function: my pseudo code:
increment = 1
"g" + increment = variable
increment = increment + 1
You should use dictionaries:
dct = {}
increment = 1
while increment <= 10:
dct[f'g{increment}'] = increment
increment += 1
This will store the variables and values in a dictionary.
So you can print it like:
print(dct)
Or to get let's say the key g3
, try:
print(dct['g3'])
You could also use list
s to store the values, like this:
lst = []
increment = 1
while increment <= 10:
lst += [[f'g{increment}', increment]]
increment += 1
And then you could print
the lst
:
print(lst)