S01 · Explorer's Field Notes

What we learned in Python

The Python from session S01, one idea at a time. The same notes are in your course folder as lessons/sessions/s01/student/python-notes.md.

Back to the S01 slides

1 · Python concept

The idea

Today's Python
print(...)Shows a value as output in the terminal.
stringA piece of text, written inside matching quotation marks: "like this" or 'like this'.
running a fileAsking Python to follow the file's instructions from top to bottom.

2 · Code we wrote

The code

print("The crystal lantern glows beside the path.")
print("A small robot waits by the landing pad.")
print("Tall stones circle an empty clearing.")

Run it from the course folder:

python lessons/sessions/s01/student/starter.py

Output:

The crystal lantern glows beside the path.
A small robot waits by the landing pad.
Tall stones circle an empty clearing.

3 · What the code means

Line by line

Each important line
print(“Show something in the terminal.”
"The crystal lantern glows beside the path."A string: the exact text to show. The quotes mark where it starts and ends. They are not printed.
)The end of what print should show.
Three print linesPython runs them in order, so three lines of output appear in the same order.

4 · Why programmers use this

Beyond this lesson

Output is how a program tells you what it is doing. Programmers use print to show results, check that code ran, and hunt for bugs.

Almost every program works with text, so strings appear in nearly all Python code, far beyond games.

5 · What we debugged

A bug worth understanding

print("The lantern flickers near the pond.')
SyntaxError: unterminated string literal (detected at line 1)

The string starts with a double quote but ends with a single quote. Python keeps looking for a matching double quote and reaches the end of the line without finding one.

Fixed:

print("The lantern flickers near the pond.")

6 · Key Python words

Words to know

Vocabulary
printA built-in Python function that shows output.
stringText inside matching quotation marks.
quotation marks" or '. The opening and closing marks must match.
outputWhat a program shows when it runs.
SyntaxErrorPython cannot read the code because it breaks a writing rule.

7 · Try it yourself

Your turn

  1. Add a fourth observation that uses single quotes: print('...').
  2. Predict what happens if you delete the closing ). Run it and compare.
  3. Print a string that contains an apostrophe, like "Nova's map". Which quotation marks make that work?