Leek Leek - 6 months ago 15
Python Question

Python make it do this

How would I be able to do this,

for i in range(10):
globals()["Var_"+str(i)] = i**2
print(Var_5)


will print 25, obv

But I be able to do this

print(Var_+str(i))

Answer

You will have evaluate the variable

eval('Var_'+str(i))