The idea
You can read a sentence with missing punctuation, but a programming language needs a dependable way to separate its parts. Treat each symbol as a signpost. Quotes mark text; parentheses supply information to a function call; a colon introduces a block after statements such as if and for. Indentation tells Python which instructions belong to that block. Use four spaces consistently in these examples.
A tiny experiment
has_key = True
if has_key:
print("The door opens.")
print("Keep exploring.")Reveal the expected output
The door opens. Keep exploring.
Read it one step at a time
- True is a Boolean value, so it is not in quotes. # can introduce a comment for a human reader.
- The colon ends the if header. The indented print belongs to that decision.
- The final print is back at the left edge. It runs whether or not the key is present.
Make one change
Change True to False. Predict both output lines before running.
Check your thinking
The door message disappears; Keep exploring. remains.
Keep following the trail
Sources & further reading
Companion notes for Coding Adventure by James Colby. Historical claims link to their sources; the examples are written for this learning trail.