0

For instance, I want to type country0 = code0 + 'abc' and then do the same thing for all integers from 0 to 9.

However, the following snippet obviously doesn't work:

for i in range(10):
  country + i = code + i + 'abc'

So, what can be done instead? Your assistance is appreciated!

Anna
  • 3
  • 2
  • 1
    Why would you even want to do this? The proper way to handle a series of related items is as a single list (or other container) - `country[i] = code[i] + 'abc'`. – jasonharper Apr 10 '23 at 15:54
  • Create the string "country0 = code0 + 'abc'" and pass it to exec(). – Yves Daoust Apr 10 '23 at 15:55
  • Why do you want to do this? As a beginner, you should never, never, never use exec(). You are creating a major security hole. Use an array as suggested by @jasonharper – Frank Yellin Apr 10 '23 at 16:10

0 Answers0