We're sorry but this app doesn't work properly without JavaScript enabled. Please enable it to continue.

This lesson's interactive features are locked, please to keep using them

Variables

Variables store data as our program runs. Up 'til now we've been printing data by passing it straight into print(), but now we'll often save data in variables so we can reuse it and change it before printing it.

A "variable" is just a name that we give to a value:

my_height = 100

Here, we've created a my_height variable and we've set it to 100. We could also create a my_name variable and set it to the string "Lane":

my_name = "Lane"

While variables can be named anything (well, almost anything. You can't have spaces in them), it's best to use descriptive names so you can remember why you created it in the first place!

Using Variables

Once you have a variable, you can access its value by using its name. For example, this prints 100:

print(my_height)

And this prints Lane:

print(my_name)

Assignment

We need to keep track of our hero's health!

On the first line of code, create a new variable named exactly player_health and set it equal to 1000.