I need to have different results for different "i"s so whenever i call for example a_8, it should return me the exact value. but python doesnt assign diferrent "i"s to it and just knows a_i.
1.for i in range(10): a_i = i + 5
I need to have different results for different "i"s so whenever i call for example a_8, it should return me the exact value. but python doesnt assign diferrent "i"s to it and just knows a_i.
1.for i in range(10): a_i = i + 5
You can use a list:
a = []
for i in range(10): a.append(i+5)
or a dictionary:
a = {}
for i in range(10): a[i] = i+5
In both cases, you can access the value later with
for i in range(10): print(a[i])
What I should use on my case? Take a look at this answer.
for i in range(10):
globals()['a_' + str(i)] = i + 5
print(a_6)
but i don't think you should use it, better use dicts instead.