-1

I am using python

a5 = [1.1,1.3,15.4,13.3]
# and 
numb = 5
aname = str('a')+str(numb) 
print(aname[0]) 

I want to make variable name using str and number and then want to get value of that variable

  • Welcome to SO, I think this question is duplicate with https://stackoverflow.com/questions/1373164/how-do-i-create-variable-variables – Mandera Nov 03 '20 at 13:43

3 Answers3

2

If your variables are global, then you can use globals()[aname] to get their value. If they are local, then use locals()[aname]

Alex P
  • 1,105
  • 6
  • 18
0

You Can Use Dictionary

name = "a"
value = True
a_dictionary = {name: value}
print(a_dictionary["a"])

the output will be True

Amr Hosni
  • 96
  • 7
0

What you want to use is the eval function (docs).

For your example:

a5 = [1.1,1.3,15.4,13.3]
# and 
numb = 5
aname = eval('a' + str(numb))
print(aname[0])