Answer the question
In order to leave comments, you need to log in
How to go from string to variable?
The question is: I form the name of a variable in a loop, but, of course, it is a string. I need to pass from a string to a variable so that when I use print, for example, the program prints out the value. Is it possible?
a1 = 1
a2 =2
for r in range(1,3):
nm = 'a'+r
print(nm)
Answer the question
In order to leave comments, you need to log in
Don't do that, use a list or a dictionary. https://qna.habr.com/answer?answer_id=1502759#answ...
How much understood it is necessary to add 'a' to numbers. If so then try this:
a = 123
a = list(str(a)) # Преобразуем в строку 'str', а потом в список 'list'
ln = len(a) # Получаем длину списка
for i in range(ln):
a[i] = a[i] + 'a' #К каждому элементу списка добавляем нужную букву
print (a) # Выводим на монитор результат
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question