Skip to content
FollowtheDamnCode

Running Python

The interactive shell, scripts, and why indentation matters.

3 minute read

Big idea

You can run Python in two ways: type a line and see the answer instantly (the interactive shell), or save lines in a .py file and run the whole file (a script).

The interactive shell

If Python is installed on your computer, typing python3 in a terminal opens the shell. It shows a >>> prompt and waits:

>>> 2 + 3
5
>>> "ha" * 3
'hahaha'

You type one line, press Enter, and Python answers. It's a calculator that speaks Python — perfect for quick experiments.

Scripts

Real programs live in files. A file of Python code is called a script and ends in .py:

# greet.py
print("Good morning!")
print("Ready to code?")

You run it from a terminal with python3 greet.py. Python reads the file from the top and runs every line.

In this course you don't need to install anything — every Run box is a little script, and the app runs it for you.

A tiny script
print("Good morning!")
print("Ready to code?")
output
Good morning!
Ready to code?

Run and edit it in the app.

Shell vs script: one surprise

In the shell, Python shows the value of whatever you type. In a script, it doesn't — a script only shows what you print:

Predict: what does this script print?
2 + 3
print(10 + 5)
"hello"
What does it print? Show the answer
15

Run and edit it in the app.

2 + 3 is worked out and then thrown away. Only the print line produces output. If you want to see something, print it.

Watch it

Indentation is part of the language

Python uses the spaces at the start of a line to mean something (you'll see why in the lessons on if and loops). For now, the rule is simple: start every line at the left edge.

Fix the bug: one line has a stray space at the start
print("Line one")
 print("Line two")
output
Line one
Line two

Run and edit it in the app.

The error says IndentationError: unexpected indent — Python's way of asking "why is this line pushed in?".

Think of it like

The shell is a conversation: you say one thing, the other person answers right away. A script is a letter: you write the whole thing, then they read it top to bottom.

Key terms

  • Shell (REPL) — Type a line, Python runs it and shows the result immediately.
  • Script — A .py file of Python code, run top to bottom.
  • IndentationError — Python's complaint about unexpected spaces at the start of a line.

Check yourself

What file extension does a Python script use?

In a script, what does the line 2 + 3 on its own show?

What causes an IndentationError?