I'm setting up a python based data program, and want to solve this 'for-loop' and 'variable assignment' problem.
I'm using python 3.7.2 and jupyter notebook
for i in range(10):
a = 1
a_i = 2
print(a)
print(a_i)
print(a_1)
1
2
---------------------------------------------------------------------------
NameError Traceback (most recent call last)
<ipython-input-14-ffb07f4b1734> in <module>
6 print(a)
7 print(a_i)
----> 8 print(a_1)
NameError: name 'a_1' is not defined
I expect a_1 should be 2 because it is assigned in the for loop. I mean a_1 ~ a_9 all should be 2, but a_i is 2. I don't understand why a_1 ~ a_9 is is not defined.