Python Names
Python doesn’t have variables, instead they have names. There is no concept of variables in Python.
Note
The notion we have of a variable is something which stores value and it can be changed through out the program life cycle. There can be different implementation of in different programming languages. For instance in C, a variable owns a memory location and stores a value in it. If a new value is reassigned, the memory location remains the same but the value is overwritten on the same location.
Understanding Names
Considering the following statement,
a = 1
Following things happen when this statement executes.
- A
PyObject
is created. This PyObject can’t be accessed by user program. It is internal to CPython implementation. typecode
is set as integer.value
is set as 1.ref
count is increased by 1.- name is
a
is bounded to thisPyObject
.
Tip
sys.getrefcount
method returns reference count to aPyObject
.