Is it possible to get the Physical memory address of a variable in python?

Michael Torrie torriem at gmail.com
Mon Jan 23 15:24:35 EST 2017


On 01/23/2017 10:49 AM, Sourabh Kalal wrote:
> how we can access the value from using id..
> like x=10
> id(x)
> 3235346364
> 
> how i can read value 10 using id 3235346364

Many objects in python such as numbers like 10 or strings are immutable;
they can never be altered once called into existance.  When you assign
to a variable, you are binding the variable name to an object.  So if
you later took your x variable and re-assigned it to value 11, the id of
x would change to reflect this new object 11.

If you could find the memory address in your example where 10 is stored,
and then modified it, you could mess up a lot of things because the
interpreter is free to optimize and to use the same 10 object every
places where 10 is assigned to a variable.




More information about the Python-list mailing list