One Pager Cheat Sheet
- This lesson will discuss variables and assignment of data values in Python for storing data temporarily.
- Variables are
placeholders
for data values that can be assigned using theassignment operator
(=) and re-assigned when needed. - Python can create variables directly by providing a name and assigning it a value, as shown in the code blocks, and then use the
print()
or variable name to display the stored value. - We need to be careful to follow the specific syntax rules when creating variables, or they may not be created correctly and cause errors.
- Creating a variable in Python is done by having a variable name followed by an
assignment operator
(=) and a value, as is the case with the code snippetwords = "Hello World!"
, which is a valid way to declare the variablewords
. - Yes, using an underscore (_) is a valid way to name variables in Python.
- Variables can be
reassigned
in Python, replacing theirprevious value
with anewer one
. - We can perform different operations on each type of variable, such as mathematical operations on integers or
concatenation
of strings. - The final value of
a
is "World". - The program prints the result of concatenating the values in the
first_name
andlast_name
variables, which isAnnaGreen
. - Creating meaningful variable names is
key
to being able to keep track of values stored in a program.