I have some code that generates two strings – digit_ and ‘x’, where x is an integer. My gut feeling is that this is a stupid question, but I can’t find an answer online. I have variables called digit_1, digit_2 … etc up to digit_9. How can I call the correct one of these without using a really long if/elif function? Is there a way of calling a variable from a concatenation of it’s name?
Sam
I have some code that generates two strings – digit_ and ‘x’, where x
Share
The cleanest way is to put the variables into a list or a dictionary, and then access them by index or by name.