Rocket is counting cargo crates in the loading bay. "Twelve crates!" he calls. He writes the number on a scrap of paper, and then the paper floats away. Weightless rooms are tricky.
Raven catches it near the ceiling. "What do you notice about this number?" she asks. "It does not say what it counts," Rocket admits. "It could be crates or cups or anything."
Nova blinks her big blue eyes. "Would you like a hint? A number is easier to find when it has a name."
A variable is a name that stores a value. Think of a box with a label on it.
The name goes on the left. The value goes on the right. The = sign means store, not equals.
crates = 12 dock = "Bay 2" print(crates) print(dock)
| The screen shows |
|---|
| 12 |
| Bay 2 |
Line 1 stores the number 12 in a box named crates. Line 2 stores the string "Bay 2" in a box named dock. Then print shows what is inside each box.
Look at these two print lines. One has quote marks and one does not.
crates = 12
print("crates")
print(crates) | Line | The screen shows | Why |
|---|---|---|
| print("crates") | crates | In quotes, it is just a string of letters. |
| print(crates) | 12 | No quotes, so Python looks inside the box named crates. |
| Variable name | Is it a good Python name? |
|---|---|
| fuel_tank | ? |
| fuel tank | ? |
| crew2 | ? |
| 2crew | ? |
crew = "Raven" job = "explorer" print(job)
ship = "Comet"
seats = 6
print(seats)
print(ship)
print("ship") Nice work! You can store a value and find it again. Tomorrow you will change what is inside a box.