Python - Variables Flashcards
Review Major Concepts of the Variables in the Python Programming Language
What is a variable?
Think of variables as labels that you can assign to values. You can also say that a variable references a certain value.
What does it mean to ‘bind’ a variable?
Binding a variable means to set a name to hold a reference to some object. Object deletion may automatically follow, by garbage collection, when no more references to an object exist.
A del statement consists of the keyword del, followed by one or more target references separated by commas (,).
What does it mean to ‘unbind’ a variable?
Unbinding a variable means to reset the variable name so it no longer holds a reference.
What does the ‘del’ statement do?
The ‘del’ statement unbinds a variable reference, although doing so is rare.
What does it mean to ‘rebind’ a variable?
Binding a reference that was already bound is also known as rebinding.
What are some naming conventions for a variable?
Cannot use a keyword.
Name some keywords.
and
break
elif
from
is
pass
with
as
class
else
global
lambda
raise
yield
assert
continue
except
if
nonlocal
return
False
async
def
finally
import
not
try
None
await
del
for
in
or
while
True
What is a ‘global’ variable?
A global variable is an attribute of a module object.
What is a ‘local’ variable?
A local variable lives in a function’s local namespace .
What does ‘namespace’ or ‘scope’ mean?
The function body, make up the function’s local namespace, also known as its local scope.
What does ‘assignment’ mean for variables in Python?
Assignment is when an value or object binds to a variable name (i.e. identifier)
Example: target = expression
What are the two types of assignments for variables in Python?
The two types of assignments for variables in Python are Plain Assignment and Augmented Assignment.
What is a ‘plain assignment’ for Python variables?
Plain assignment to a variable (e.g., name = value) is how you create a new variable or rebind an existing variable to a new value.
What is an ‘augmented assignment’ for Python variables?
Augmented assignment can
* rebind a variable,
* ask an object to rebind one of its existing attributes or items, or
* request the target object to modify itself.
Augmented assignment (e.g., name += value) cannot, per se, create new references.