In Python we declare and assign a variable like this:
a = 100
Most tutorials say a variable a
now refers to the int
object 100
.
Does that mean the variable a
contains the address where an int
object is stored ?
In Python we declare and assign a variable like this:
a = 100
Most tutorials say a variable a
now refers to the int
object 100
.
Does that mean the variable a
contains the address where an int
object is stored ?
As John Coleman points out, python variables are just names in a dictionary, where the values pointed to by the keys are addresses. In the CPython implementation of python, you can find the memory address pointed to by a python variable by using the built-in function id()
.
For more information about this dictionary refered to in my answer, see this StackOverflow post