Rocket is making name signs for the docking hatches. He stores "Moon" in one variable and "Dock" in another. Then he joins them with a plus sign. The sign reads MoonDock, all squished together.
"Let's see what happens with numbers," Rocket says. He joins the string "3" and the string "4". The screen shows 34, not 7!
Raven tilts her head. "What do you notice about the quote marks?" she asks. Nova glows. "I found a pattern. Strings and numbers follow different rules."
When both sides of + are strings, Python glues them together. It does not add a space unless you give it one.
first = "Moon"
second = "Dock"
print(first + second)
print(first + " " + second)
print("3" + "4")
print(3 + 4) | Line | The screen shows |
|---|---|
| print(first + second) | MoonDock |
| print(first + " " + second) | Moon Dock |
| print("3" + "4") | 34 |
| print(3 + 4) | 7 |
a = "Star" b = "light" print(a + b)
| Line | What someone says it shows | True or false? |
|---|---|---|
| print("5" + "5") | 10 | ? |
| print(5 + 5) | 10 | ? |
| print("Bay" + "2") | Bay2 | ? |
| print("Go" + " " + "now") | Gonow | ? |
planet = "Mars"
base = "Camp"
print(planet + base)
print(base + " " + planet)
print("1" + "5")
print(1 + 5) | Line | What someone says it shows | True or false? |
|---|---|---|
| print("8" + "1") | 81 | ? |
| print(8 + 1) | 81 | ? |
| print("Hi" + " " + "Nova") | Hi Nova | ? |
| print("Ten" + "4") | Ten 4 | ? |
Good thinking! You know that quote marks change what + does. Tomorrow you will build a full fuel report.