3.2 Variables
Variables are assigned using the =
sign:
variable_name = value
For example:
composer = "buxtehude"
year = 1637
The variable name can be almost anything. Here are some general rules to consider when naming a variable:
- The name must start with a letter or underscore
- The name can only consist of letters, numbers, or underscores
- Variables are case sensitive (i.e. Python interprets
my_number
,MY_NUMBER
, andMy_Number
as different variables) - Python has a set of “reserved words” that cannot be used as variable names. These are words that already have a set meaning in Python, such as
True
,False
,for
, andif
. A full list can be found here.