Python remembers strings and numbers by assigning them to a “variable” with a relevant name. For example, a variable can be used to remember a long string:

In the example above

  1. myname is the variable. It has a relevant name, and no quotes
  2. The = operator is used to assign a value (string or number) to the variable
  3. The value of a variable can be reassigning, ie. it can vary (hence variable)

Variables can also be used to store and remember numbers, and they can be used to do calculations:

Variable names

Python variables can be called almost anything you want, with the following rules:

  1. Python variables must not include a space or other punctuation symbols, except the underscore character _ (sometimes used to represent a space), eg. my_name
  2. Must not begin with a number (0-9), eg. car100 is ok, but 100car is not
  3. Must not be a reserved word, ie. an existing Python command, such as print.

Variable Keywords

  • assignment: defining a variable with a value, using the = operator, eg. myname = “BugZoid”
  • variable: a way to represent, store and remember a value