Chapter 2 Key Takeaways
One-Sentence Summary
Python is an interpreted language that you interact with through the terminal, the REPL, and script files — and your first programs use print() and input() to communicate with the user.
Core Concepts
-
Python is interpreted. The Python interpreter reads and executes your code line by line — no separate compilation step. This enables the fast write-run-fix cycle that makes Python great for learning.
-
The terminal is essential. It's a text-based interface to your computer. Learn
cd(change directory),ls/dir(list files), andpwd(print working directory) to navigate. -
The REPL is your sandbox. Type
pythonto enter the REPL (>>>). Use it to experiment with expressions, test ideas, and explore how Python works — before committing code to a file. -
Scripts are saved programs. Write code in a
.pyfile, save it, run it withpython filename.py. Always save before running. -
print()produces output. Usesepto change the separator between arguments andendto change what appears at the end of the line. -
input()collects text. It always returns a string, even if the user types a number. -
Comments explain why, not what. Use
#to add notes for human readers. Python ignores everything after#. -
Error messages are your friend. Read the last line first (error type + description), then check the line number to find the problem.
Essential Commands
| What You Want to Do | Command |
|---|---|
| Check Python version | python --version |
| Start the REPL | python |
| Exit the REPL | exit() or Ctrl+D (Ctrl+Z on Windows) |
| Run a script | python filename.py |
| List files in current directory | ls (macOS/Linux) or dir (Windows) |
| Change directory | cd foldername |
| Go up one directory | cd .. |
| Create a folder | mkdir foldername |
Common Error Types
| Error | What It Means | Common Cause |
|---|---|---|
SyntaxError |
Python can't parse your code | Missing quote, parenthesis, or colon |
NameError |
Python doesn't recognize a name | Typo in a variable name, or using a variable before defining it |
IndentationError |
Unexpected spaces at the start of a line | Extra or missing indentation |
Key Functions
# Output
print("text") # basic output
print("a", "b", sep="-") # custom separator
print("no newline", end="") # suppress newline
# Input
name = input("Prompt: ") # get user input (always returns a string)
# F-strings (preview — covered fully in Ch. 3)
print(f"Hello, {name}!") # insert variable value into string
Checklist: Before Moving to Chapter 3
- [ ] Python 3.12+ installed and verified (
python --version) - [ ] VS Code installed with Python extension
- [ ] Comfortable navigating folders in the terminal
- [ ] Can write and run a
.pyscript - [ ] Built and run TaskFlow v0.1
- [ ] Can read a Python error message and identify the problem