0

i have a program making the string "aX". i'm then putting it into an equation where i need to call the variable that i named aX.

letters = "abcdefgh"
for i in letters:
   posX = i + "X"
   posX = int(posX)
   posY = i + "Y"
   posY = int(posY)

can someone help my figure out how to call aX and aY instead of a string?

i tried converting posX and posY into integers , but i cant because it is trying to convert the string "aX" into an integer.

  • 4
    Rather than do it like this, it's *much* better to keep your variables in a dictionary. Then you can just index into it, and you won't be polluting your namespace. – Tom Karzes May 08 '23 at 21:25
  • Dictionary keys can have any string name you want. Why do you want to make custom variable names dynamically? – JacobIRR May 08 '23 at 21:27

0 Answers0