Lesson goal: Introduction to Variables

Previous: Speaking numbers properly | Home | Next: Mathematical expressions with variables

Variables are an extremely important aspect of programming. By look, variables are simply single word names, like score to keep track of the score in a game, count to keep track of hits on a website, or x as a variable in a math problem.

By purpose, variables are used to keep track of some information in a program that may change. For example, at one moment in a game, the score might be 100. A few seconds later, it might be 200.

In this lesson, you'll be able experiment with variables and see how they work.
variable=value
Move the mouse over a dotted box for more information.

Note that the name of your variable does not have to be "variable" as shown above. Often it is better to choose a variable some name that gives it some context. If you were keeping score in a computer game for example, you'd call the variable score or game_score. In mathematics, x and y are often used as variables, but with the computer and keyboard, you are free to have more descriptive variables. How about money or amount_left or EmployeeName? The only condition on variable names is that they start with a letter of the alphabet, contain no spaces, and typically cannot contain any funny characters either (like !@#$%^&). Variables can contain the underbar _ however.

Now you try. Try setting a variable to some value, then printing that value through the variable name.

Type your code here:


See your results here: