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

  1. Python is interpreted. You run your source file directly: the interpreter checks the whole file, translates it to bytecode behind the scenes, and executes it top to bottom — no separate compile step for you. This enables the fast write-run-fix cycle that makes Python great for learning.

  2. The terminal is essential. It's a text-based interface to your computer. Learn cd (change directory), ls/dir (list files), and pwd (print working directory) to navigate.

  3. The REPL is your sandbox. Type python to enter the REPL (>>>). Use it to experiment with expressions, test ideas, and explore how Python works — before committing code to a file.

  4. Scripts are saved programs. Write code in a .py file, save it, run it with python filename.py. Always save before running.

  5. print() produces output. Use sep to change the separator between arguments and end to change what appears at the end of the line.

  6. input() collects text. It always returns a string, even if the user types a number.

  7. Comments explain why, not what. Use # to add notes for human readers. Python ignores everything from # to the end of the line.

  8. 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 just exit in 3.13+), or Ctrl+D (Ctrl+Z then Enter on Windows)
Run a script python filename.py
List files in current directory ls (macOS/Linux) or dir (Windows)
Show where you are pwd (macOS/Linux/PowerShell) or cd (Command Prompt)
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, so none of the file runs Missing quote, parenthesis, or colon
NameError Python doesn't recognize a name Typo (including wrong capitalization, like Print), 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.13+ installed and verified (python --version)
  • [ ] VS Code installed with Python extension
  • [ ] Comfortable navigating folders in the terminal
  • [ ] Can write and run a .py script
  • [ ] Built and run TaskFlow v0.1
  • [ ] Can read a Python error message and identify the problem