Python · Stage 1 · Storing Information · Lesson 8 of 50

Naming Variables

Choose valid, readable variable names that explain what a value means.

A variable name is the label you choose for a stored value. Python has naming rules, and programmers use simple habits to make names readable.

A name may contain letters, numbers, and underscores. It cannot begin with a number. It cannot contain spaces or hyphens.

favorite_color = "green"
Line-by-line explanation
  1. favorite_color uses letters and an underscore, so it is valid.
  2. The underscore joins two words because spaces are not allowed.
  3. "green" is stored under that name.
student_age = 12
Line-by-line explanation
  1. student_age clearly describes the information.
  2. = stores a value.
  3. 12 is the stored value.