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. 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.

  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 after #.

  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 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 .py script
  • [ ] Built and run TaskFlow v0.1
  • [ ] Can read a Python error message and identify the problem