1. Variables,objects and references
Variable creation:
A variable (i.e.,name),like a, is created when your code first assigns it a value.Future assignments change the value of the already created name
Variable Types:
A variable never has any type information or constraints associated with it.
The notion of type lives with objects, not names. They always simply refer to a particular object at a particular point in time.
Variable Use:
When a variable appears in an expression, it is immediately replaced with the object that it currently refers to . whatever it might be. Further, all variables must be explicitly assigned before they can be used; referencing unassigned variable results in errors.
In sum, variables are created when assigned, can reference any type of object, and must be assigned before they are referenced.
variables and objects are stored in different parts of memory and are associated by links(the link is a pointer, Internally, the variable is really a pointer to the object’s memory space created by running the literal expression)
variables always link to object and never to other variables, but larger objects may link to other objects
these links from variables to objects are called references in Python -that is , a reference is a kind of association, implemented as a pointer in memory.
• Variables are entries in a system table, with spaces for links to objects.
• Objects are pieces of allocated memory, with enough space to represent the values for which they stand.
• References are automatically followed pointers from variables to objects.
At least conceptually, each time you generate a new value in your script by running an expression, Python creates a new object (i.e., a chunk of memory) to represent that value.
As an optimization, Python internally caches and reuses certain kinds of unchangeable objects, such as small integers and strings (each 0 is not really a new piece of memory—more on this caching behavior later).
But from a logical perspective, it works as though each expression’s result value is a distinct object and each object is a distinct piece of memory.
(Technically speaking, objects have more structure than just enough space to represent their values.
Each object also has two standard header fields: a type designator used to mark the type of the object, and a reference counter used to determine when it’s OK to
reclaim the object. )