Storing Information in Code
Up until now, we’ve been printing values directly onto the screen.
For example:
print(100)But what if we want to remember that number and use it later? That’s where variables come in. A variable is like a labelled storage box inside your program. You give the box a name, and you put data inside it. Later, you can open that box and use whatever is stored inside.
For example:
height = 180 name = "Cruz"Here: -
height stores the number 180
- name stores the text "Cruz"
The equals sign (=) means “store this value in this variable.”
Assignment:
In World of Software Engineering, we need to keep track of our hero’s health. Create a variable named: player_health Set it equal to: 1000 Then print it using:
In World of Software Engineering, we need to keep track of our hero’s health. Create a variable named: player_health Set it equal to: 1000 Then print it using:
print(player_health)
Create the variable
print(player_health)