Python doesn't really have variables*, Python has names. See Facts and myths about Python names and values by Ned Batchelder.
Therefore, C-like concepts of pointers don't translate well to Python. var
is just a name that points to the integer object 5
; by appending var
to array
, you created another reference to that object, not a pointer to var
.
Whatever you're trying to do might be better serviced by, for example, a dictionary:
vars = {"var": 5}
array = []
array.append("var")
vars[array[0]] = 1
print(vars[array[0]]) # prints "1"
print(vars["var"]) # ditto
*In the abovementioned article, Ned Batchelder writes that "names are Python's variables". In other words, Python does have variables, but they work in a different way than variables in, say, C or Java.