Exam 2 Flashcards
reference
In Python, a variable is a location in memory (on the stack) that holds a reference to an object. The ‘stack’ is static memory set by the bytecode compiler. The stack is also known as ‘local storage’.
values
Conversely, values of the variables are stored on the ‘heap’ which is dynamic memory managed by the PVM or JIT compiler depending on whether CPython or PyPy is the implementation. The heap is also known as ‘free storage’.
All variables in Python reference objects.
All variables in Python reference objects. Each variable is an address location on the stack and it holds a reference (address) to the actual storage location in memory where the value is stored. This method of variable storage is different than that employed in some other languages. For instance, in C++, the variable location actually stores the value and not a reference to the value.
Variables (the references to the actual values)
Variables (the references to the actual values) and the values to which they point are both stored in RAM (random access memory).
Variables (the references)
Variables (the references) are stored on the program stack.
Values
Values are stored on the program heap.
Variable values
Variable values, the data stored at a location in memory, can change while the program is running.
data type
The data type to which a variable references can change.
If two variables
If two variables contain the same value and are in the same scope they point to the same object in memory
out of scope
When a variable goes out of scope it is marked as ready for deletion.
When a program exits
When a program exits, all references to the program’s variable data are lost and the memory is released back to the operating system.
scope
Variables created inside a function have scope which is local to that function. This means that those variables are not visible from and cannot be used outside of that function. This is known as ‘function-level scope’.
Variables in some languages
Variables in some languages like C++ and Java have block-level scope. Python uses function-level scope which means variable visibility is limited to the function containing the variable. If a variable is not in a function, it is visible within the entire module. PHP and Javascript also use function-level scope.
module-level or global scope
Variables created outside of all functions have module-level or global scope and are visible to all code in that module.
Identifiers
Identifiers provide a convenient means to identify variables which is much nicer than using a hexadecimal addresses. An identifier is a name for a variable, function, module, class, or any other object.