Chapter 1
Running Code
The first Python habit: write a small program, run it, read what happens, edit one thing, and run again.
What this chapter does
Before Python can help with arrays, plots, or models, the reader needs the basic run loop. This chapter makes code, output, errors, scripts, and interactive sessions concrete.
Lessons
Read these in order.
The chapter opening gives the main idea. Move through these lessons next; each page reuses ideas from the pages before it.
- 01What Python Runs
Code as exact instructions, output as evidence, and expressions as values.
- 02Installing and Checking Python
How to check for a Python 3 runtime before installing anything else.
- 03Scripts and the Terminal
Running a saved Python file from the terminal and reading its output.
- 04Interactive Sessions
Using the Python prompt for small checks while keeping longer work in scripts.
- 05Reading Output and Errors
Output as evidence and errors as reports about where Python got stuck.
- 06Editing and Rerunning
Changing one thing, rerunning, and comparing the result with expectation.
You are ready when
- Run a small Python script.
- Tell code apart from output.
- Use an interactive session for tiny checks.
- Read simple errors as debugging information.
- Edit one line, rerun, and explain the changed output.
Where this leads
- Names, Values, and Types
- Branches and Loops
- Functions