LESSON 2

How Python Works

Learning objective: Learn how Python runs your code line by line.

Understand

Python is an interpreted language.

Python code is run by the interpreter, which reads and executes your script top to bottom. You can run whole files or type commands one at a time in an interactive shell. There is no separate compile step to worry about.

Analogy: The interpreter is like a translator reading your instructions aloud one line at a time.

See It in Action

Two lines run in order:

print("First")
print("Second")
How it works: Python runs the first line, then the second, so the output appears in that order.

Try It Yourself

  1. Run a script with two print lines.
  2. Swap their order and rerun.
  3. Try typing a command in the interactive shell.

Quick Quiz

How does Python run your code?

Challenge

Write a short script whose output order proves lines run top to bottom.

Success condition: Your output appears in the same order as your lines.