
Code
Give It a Name
A variable is a name that remembers a value, like a label
stuck on a jar. You create one with a single = sign:
guide = "Pip"
lanterns = 7
Read = as "store": store "Pip" under the name guide.
Now you can use the name anywhere instead of the value:
print(guide) # Pip
print("Guide:", guide) # Guide: Pip
print("Lanterns:", lanterns) # Lanterns: 7
Notice: guide has no quotes, so Python looks up what's
inside the jar. "guide" with quotes would just print the word guide.
You can give print several things separated by commas;
it shows them in order with a space between each.
Name rules: use lowercase letters, digits and _
(like oil_left), and don't start with a digit.
Assignment
- Create a variable
islandthat stores the text"Emberreach". - Create a variable
lanternsthat stores the number3(no quotes). - Print them using commas so the output is exactly:
Island: Emberreach
Lanterns: 3- Create a variable
islandthat stores the text"Emberreach". - Create a variable
lanternsthat stores the number3(no quotes). - Print them using commas so the output is exactly:
Island: Emberreach
Lanterns: 3main.py Python sleeping
Press Run to try your code, then Check to test it.