This is a simple python language code, and I want to know the address of variable a:
if __name__ == '__main__':
a = 2
print(a)
print(id(2))
print(id(a))
The output is:
2
140704200824512
140704200824512
But I don't think the address of variable a is 140704200824512. I think 140704200824512 is the address of data 2.
As shown below, what is the value of the red question mark?
Maybe the figure above is totally wrong because some documentation says the variables actually don't exist in python. They are just entries in namespace. But I still don't understand the internal principle.
In C programming language, it is easy to understand the relationship between variable and data, but in python programming language, it is hard.
This is a simple C language code:
#include <stdio.h>
int main(){
int a = 2;
printf("%d\n",a);
printf("%x\n",&a);
}
The output is:
2
60fe1c
The relationship between variable a and data 2 is simple: a stores 2. Just as the following:
Can someone answer my question?