0

I have a list

test=['num1' ,'num2']

and variables

valuenum1 = 'x'
valuenum2 = 'y'

I want to do the following loop

for i in test:
       print(value{i})

Which I cant do because value is not a string, so the {i} method is useless. Is there a way to do loop the value in test so I can print valuenum1 and valuenum2?

griefter
  • 37
  • 5
  • 4
    You don't want variables named like that. You want a single dict like `values = {'num1': 'x', 'num2': 'y'}`. – chepner Feb 01 '23 at 18:24
  • If you're bound and determined to make this work for a very good reason, have a look at [Getting the name of a variable as a string](https://stackoverflow.com/questions/18425225/getting-the-name-of-a-variable-as-a-string) but there are better ways to store and access your data – G. Anderson Feb 01 '23 at 18:33

0 Answers0