0
var_1 = 5
var_2 = 6
var_3 = 7

for i in range(3):

    string = "var_{}".format(i+1)

string will be var_1, var_2 and var_3 how would I replace them with 5, 6 and 7?

  • 1
    Do not make separate variables like that in the first place, instead use a list or dict to store all the values and then you can look them up using the `i` value as an index. – Karl Knechtel Nov 12 '20 at 14:43
  • Yes you're totally right. But my question is about handling this case if exists – Adel Abu Hashim Nov 13 '20 at 19:16

0 Answers0