I have looked around the forums and I can't seem to find an answer (and there might not be one actually) as to whether or not you can get the name of a variable or the value by using its memory location in Python. In other words, when I declare a = 10
and assign the value 10
to the variable 'a'
, and then I use the id()
function on 'a'
I get the location in memory where the value for 'a'
is stored. Is there a way to, say, print the variable name ('a')
or the value ('10')
by referencing the value that id()
returns (either the decimal value or converting the decimal value to hex with the hex()
function)? I tried a few things like print(id(variable-name))
and just print(decimal-value-from-id)
and no luck. Any help would be greatly appreciated and thank you in advance!
Cheers!