0
x = [1,2,3]
y = [5,6,7]
z = input("Enter which variable to use x or y: ")

now I want use the variable x or y depending on whether the input is "x" or "y"

Aplet123
  • 33,825
  • 1
  • 29
  • 55
  • 1
    Does this answer your question? [How do I create variable variables?](https://stackoverflow.com/questions/1373164/how-do-i-create-variable-variables) – Tomerikoo Nov 03 '20 at 12:05

2 Answers2

6

Please, please, please, please, please don't use runtime variable reading. Instead, just use a dict:

lists = {
    "x": [1, 2, 3],
    "y": [5, 6, 7]
}
z = input("Enter which variable to use x or y: ").strip()
print("Your variable is: " + str(lists[z]))
Aplet123
  • 33,825
  • 1
  • 29
  • 55
1

You can use locals() if you really need it's very very unsafe.

x = [1,2,3]
y = [5,6,7]
z = input("Enter which variable to use x or y: ")
locals().get(z)
Equinox
  • 6,483
  • 3
  • 23
  • 32