

0 / 2 embers
0 / 3000 xp
click for more info
Complete a lesson to start your streak
click for more info
Difficulty: 4
click for more info
Not enough gems
Cost: 6 gems
1: Variables
incomplete
2: Variables Vary
incomplete
3: Math
incomplete
4: Negative Numbers
incomplete
5: Comments
incomplete
6: Variable Names
incomplete
7: Basic Variable Types
incomplete
8: F-Strings in Python
incomplete
9: NoneType Variables
incomplete
10: NoneType Quiz
incomplete
11: Dynamic Typing
incomplete
12: Math With Strings
incomplete
13: Multi-Variable Declaration
incomplete
14: Boots
incomplete
15: Spellbook
incomplete
16: Character Report
incomplete
Back
ctrl+,
Next
ctrl+.
This lesson's interactive features are locked, please to keep using them
Variables are how we store data as our program runs. Up 'til now we've been printing data by passing it straight into print(). Now we're going to save the 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. For example, we can make a new variable named my_height and set its value to 100:
my_height = 100
Or we can define a variable called my_name and set it to the text string "Lane":
my_name = "Lane"
We have the freedom to choose any name for our variables, but they should be descriptive and consist of a single "token", meaning continuous text with underscores separating the words.
Once we have a variable, we can access its value by using its name. For example, this will print 100:
print(my_height)
And this will print Lane:
print(my_name)
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.