Learn Python
>>> getting_started.interpreter

The Python Interpreter: Interactive vs Script Mode

#concept

There are two different ways to hand code to the Python interpreter. Typing python with no filename starts interactive mode β€” often called the REPL, for Read-Eval-Print Loop β€” which shows a >>> prompt and evaluates one statement at a time, immediately printing the result of any bare expression. Typing python filename.py starts script mode, which reads the entire file top to bottom and runs it in one pass, printing only what you explicitly tell it to print.

Both modes use the exact same interpreter underneath β€” the difference is just how code arrives: one line at a time and interactively, or as a whole finished file.

#how it works
1

Interactive mode starts with no filename

Typing python (or python3) alone opens a >>> prompt right there in the terminal.

2

You type one statement, it runs immediately

Each line you type is evaluated the moment you press Enter β€” there's no waiting for a whole program to finish.

3

Bare expressions echo automatically

Typing an expression like 2 + 2 with no print() shows its result anyway β€” the REPL echoes the value of the last expression by default.

4

Script mode starts with a filename

Typing python filename.py hands the whole file to the interpreter at once.

5

Only explicit output shows up

In script mode nothing is echoed automatically β€” if a line isn't wrapped in print(), its value simply disappears once evaluated.

#example
2 + 2
name = "Ada"
name
print(name)
Output
4
'Ada'
Ada
1Typing 2 + 2 and pressing Enter shows 4 immediately β€” the REPL evaluates the expression and echoes its value with no print() needed.
2name = "Ada" is an assignment, not an expression, so nothing is echoed β€” assignments never produce a visible value on their own, which is why there is no output for this line.
3Typing just name afterward re-evaluates it as an expression, so its value is echoed β€” notice it appears with quotes ('Ada'), which is how the REPL displays a string's exact representation.
4print(name) shows Ada with no quotes β€” print() converts the value into a plain readable string, while the REPL's auto-echo shows the value's literal, unambiguous representation.
#use cases
Quickly testing how a function or expression behaves before adding it to a real script
Exploring an unfamiliar library interactively β€” import it and inspect what it offers with tab-completion
Tools like IPython and Jupyter notebooks, which extend the same interactive idea with richer, persistent output
Dropping into an interactive session mid-program (for example with breakpoint()) to inspect variables while debugging

Recommended resourcesAffiliate links Β· may earn us a commission

Recommended for learners

Structured coding coursesVideo courses that pair well with visual practice β€” pick one language and go deep.Browse courses Pro code editor & AI assistantWrite, debug and explain code faster while you practice the patterns here.Try it free Classic DSA interview booksThe reference books interviewers themselves learned from β€” great next to the visualizers.See the books

Practice what you learned

Re-implement each visualized algorithm in Python yourself β€” building beats watching.