I can't seem to turn a string into a corresponding variable.
point1 is a defined tuple (100, 100), but once I combined "point" and 1, it stays a string and doesn't return (100, 100).
I'd like to know if there's a way to make the string that existing variable, or if there's a way to combine "point" and "1" without turning either of them into strings. (I combined "point" and "1" using format.)
point1 = (100, 100)
def point(step):
return "point{}".format(step)
print(point1)
print(point(1))
print(tuple(point(1)))
I want "point(1)" to return "(100,100)" but it returns "point1".
.
Edit(??): Thank you so much everyone! All of these answers helped so much! ^^
My question is unique from the variables variables question, because this one is solved simply by putting the string inside eval() or globals().
eg:
point1 = (100,100)
print(point1)
print("point1")
print(eval("point1"))
# or
def point(step):
return globals()[f"point{step}"]
print(point(1))
This gives me
(100, 100)
point1
(100, 100)
(100, 100)