PCC·01 · Chapter record
Getting Started
Chapter 1 — how Python actually runs your code
The book's own Chapter 1 spends most of its time on installing Python and a text editor per operating system — not needed here, since every demo on this site already runs in-browser. These three sessions keep the ideas that carry over: what the interpreter actually does, the two ways to run code, and how to read an error when something breaks.
The Python Interpreter
Concept
- Every Python program starts as a plain text file saved with a .py extension — a script.
- A program called the interpreter reads your file from the very first line to the very last and carries out each instruction immediately.
- There's no separate "build" step the way some other languages use — whatever line the interpreter reaches is the line that runs next.
- When it sees print followed by parentheses, it displays whatever is inside them on the screen.
- A good editor helps with syntax highlighting — coloring function names, strings, and keywords differently — so mistakes are easier to spot before you even run the file.
Key Terms
- interpreter
- the program that reads your .py file and runs it line by line
- script
- a saved .py file containing a full program
- syntax highlighting
- an editor's way of coloring code by what each part means
Exercise
Change the message inside print() to introduce yourself, then run it again.
Script vs. Interactive Prompt
Concept
- There are two ways to run Python code.
- Saving instructions in a .py file and running the whole thing at once is running a script — that's how real programs are built.
- Python also has an interactive prompt, shown as
>>>in examples, which runs one line at a time and immediately shows you the result. - In a script,
2 + 3sitting on its own line does nothing visible — you have to print() it to see the result. - At the interactive prompt, Python echoes back the value of anything you type — that's why examples show
>>> 2 + 3followed directly by5, with no print() at all.
Key Terms
- interactive prompt
- Python's line-by-line mode, shown as >>> in examples — also called a REPL
- >>>
- the prompt symbol shown before code you type at the interactive prompt
- expression
- something Python can reduce to a single value, like 2 + 3
Exercise
Which of these would only show a visible result if typed at the interactive prompt, not inside a saved script: 2 + 3, or print(2 + 3)?
Reading a Traceback
Concept
- When Python hits code it can't run, it doesn't fail silently — it prints a traceback: a report showing which line caused the problem and what kind of error occurred.
- A SyntaxError means Python couldn't even understand the structure of what you wrote — often a missing colon, a missing quote, or a mismatched parenthesis.
- Read a traceback from the bottom up — the last line names the error type, and the line just above it points to roughly where it happened.
- Not every error is a SyntaxError: a misspelled function or variable name raises a NameError instead, because Python understood the structure fine but couldn't find anything by that name.
Key Terms
- traceback
- the report Python prints when it hits an error it can't recover from
- SyntaxError
- raised when Python can't understand the structure of your code
- NameError
- raised when Python can't find anything matching the name you used
Exercise
Line 4 above is prin("Hello!") — what type of error would this raise, and what's the one-character fix?