How to Get to a New Line in Python Shell: Complete Guide

Press Enter at the >>> prompt and your code runs immediately — so how do you tell the Python shell that you are not done yet? And if you actually wanted to print a line break, why does the shell seem to have no "new line" key at all? Both questions come down to how the interactive interpreter reads input and how Python spells a newline character.

This guide answers both sides of that question: continuing a statement across several lines without triggering execution, and producing line breaks in your output. Along the way you will learn exactly when the shell switches to the ... prompt, how to finish a block cleanly, how to escape when things go wrong, and what Python 3.13 through 3.15 changed about multi-line editing in the default REPL.

Table of Contents#

  1. What "Getting to a New Line" Means in the Python Shell
  2. How to Continue a Statement on the Next Line
  3. How to Finish a Multi-Line Block and Run It
  4. How to Print a New Line in the Python Shell
  5. Practical Recipes for Multi-Line Input
  6. Troubleshooting: When New Lines Do Not Work
  7. Smarter Ways to Type Multi-Line Code
  8. Python 3.13 to 3.15: A Much Friendlier REPL
  9. Best Practices and Power-User Tips
  10. Conclusion
  11. References

1. What "Getting to a New Line" Means in the Python Shell#

1.1 The REPL at a glance: >>> versus ...#

When you start Python from a terminal (run python or python3), you enter interactive mode, a Read-Eval-Print Loop that evaluates each statement as soon as it is complete. The shell shows two prompts:

PromptNameMeaning
>>>Primary promptThe shell is ready for a complete statement.
...Secondary promptThe shell is waiting for continuation lines.

This distinction is the heart of the problem. A simple statement — an assignment, a function call, an expression — is finished the moment you press Enter, so the shell runs it right away:

>>> price = 12
>>> price * 3
36

A compound statement (if, for, while, def, class, with, try) is not finished when its line ends with a colon, and an unclosed bracket or quote is not finished either — so in both cases the shell drops to ... and waits. Continuation lines are exactly what the ... prompt is for.

1.2 Two goals, one keyword#

Searchers asking how to get to a new line in the Python shell usually mean one of two things:

  1. Continue input — move to the next line so a loop, function, or long expression is not executed prematurely.
  2. Produce a line break in output — make print() or a string start a fresh line, usually with \n.

Sections 2 and 3 cover the first goal; section 4 covers the second. Both matter, and mixing them up is common when you are just starting out.

2. How to Continue a Statement on the Next Line#

The shell moves to the ... prompt whenever the statement you are typing is incomplete. There are three ways to make that happen deliberately.

2.1 End a line with a colon to open a code block#

Python marks the start of a block with a colon. End a line with : and the shell knows more lines must follow — the indented suite of the block:

>>> for step in range(1, 4):
...     print(f"step {step}")
...
step 1
step 2
step 3

What happened here:

  1. for step in range(1, 4): ends with :, so the shell switches to ....
  2. The body line is typed with indentation (4 spaces, per convention).
  3. An empty line marks the block as finished, and only then does the loop run.

The same rule applies to if, while, def, class, with, and try statements — anything that introduces an indented block.

2.2 Leave a bracket open for implicit line joining#

Expressions inside parentheses (), square brackets [], or curly braces {} can span as many lines as you like, because the shell keeps prompting with ... until every bracket is closed. This is called implicit line joining:

>>> reading = {
...     "sensor": "A1",
...     "celsius": 21.5,
...     "logged_at": "2026-10-12T09:30:00Z",
... }
>>> print(reading["sensor"])
A1

Useful details worth knowing:

  • Continuation lines inside brackets may carry comments (# ...) and may be indented any way you like.
  • Blank lines are allowed inside the brackets — they do not end the statement.
  • Closing the bracket completes the statement, so the shell executes it right after that line.

Long function calls are the most common use:

>>> total = sum(
...     [12, 30, 5]
... )
>>> total
47

2.3 End a line with a backslash for explicit line joining#

When you genuinely cannot wrap an expression in brackets, put a single backslash at the end of the physical line. The shell then joins it with the next one:

>>> month, day = 10, 12
>>> is_valid = 1 <= month <= 12 and \
...            1 <= day <= 31
>>> is_valid
True

Two sharp edges to remember:

  • A backslash must be the last character on the line. A space after the backslash means it is not a line continuation (PEP 8 calls this out specifically, and many projects reject such lines automatically).
  • A backslash cannot continue a comment, and it cannot continue a token other than a string literal.

For readability, PEP 8 recommends preferring implicit continuation in parentheses over backslashes:

# Preferred
>>> is_valid = (1 <= month <= 12 and
...             1 <= day <= 31)
 
# Acceptable only when brackets do not fit the situation
>>> is_valid = 1 <= month <= 12 and \
...            1 <= day <= 31

2.4 Fit more on one line with semicolons and single-line suites#

Going the other direction: sometimes you want fewer new lines. Separate simple statements with a semicolon, and write a whole compound statement on one line with a suite after the colon:

>>> import math; print(math.pi)
3.141592653589793
>>> for label in ["go", "stop"]: print(label)
...
go
stop

Notice the subtle behavior in the second example: even a one-line compound statement ends with :, so the shell still shows ... and waits for a blank line before running it. If the next line you type is more code instead of an empty line, the shell tries to parse it as part of the block and you get a SyntaxError. (Section 6.4 covers this in detail.)

3. How to Finish a Multi-Line Block and Run It#

Typing the new line is only half of the task; the shell also needs a clear signal that you are done.

3.1 The blank line rule in the classic REPL#

In the traditional interactive interpreter (Python 3.12 and earlier, or any version started with PYTHON_BASIC_REPL set), a compound statement is submitted when you press Enter on an empty continuation line:

>>> def celsius_to_fahrenheit(c):
...     f = (c * 9 / 5) + 32
...     return round(f, 1)
...
>>> celsius_to_fahrenheit(25)
77.0

People often describe this as hitting Enter twice: once to step from the last statement of the block onto a fresh ... line, and once more on that empty line to submit the whole block. Expressions inside unclosed brackets are the exception — they run as soon as the closing bracket is typed, with no blank line required.

3.2 Closing the quotes or brackets ends the statement#

For strings and bracketed expressions, completeness is syntactic, not a key press. A triple-quoted string continues across lines until you type the closing quotes:

>>> query = """SELECT id, name
... FROM users
... WHERE active = 1"""
>>> print(query)
SELECT id, name
FROM users
WHERE active = 1

Inside a triple-quoted string the ... prompt is still shown, but the shell is not looking for a block — it is waiting for the literal to end.

3.3 What changed in Python 3.13 and later#

If you are on Python 3.13 or newer, the default interactive shell (adapted from the PyPy project's pyrepl) treats a multi-line statement as one editable chunk. The practical differences:

  • You can move the cursor through the whole block with the arrow keys and fix any line before running it.
  • Pressing Enter in the middle of the block starts another line instead of submitting half-written code; when the statement is complete, it executes as usual.
  • Recall the entire block with a single Up-arrow press instead of replaying it line by line.

The blank-line rule for typed compound statements still applies, so the habit from section 3.1 keeps working everywhere.

4. How to Print a New Line in the Python Shell#

If your question is about output rather than input, this section is for you. Python spells a line break as \n — an escape sequence for the ASCII linefeed character.

4.1 The \n escape sequence#

Anywhere inside an ordinary string literal, \n inserts one newline:

>>> print("Line 1\nLine 2")
Line 1
Line 2

To show a literal backslash followed by n, double the backslash (\\n) or use a raw string, where escape sequences are left untouched:

>>> print("C:\\temp\\new")
C:\temp\new
>>> print(r"escape sequence: \n")
escape sequence: \n

4.2 print() and its end parameter#

Every call to print() writes the values you give it, separated by sep (a single space by default), and then writes end — which defaults to "\n". That trailing newline is why each print() call starts a fresh line:

>>> print("first")
first
>>> print("second")
second

You can control it. With an empty end, no line break is written, so the next output continues on the same display line:

>>> print("Loading", end="")
>>> print("... done")

On screen the two calls share a single output line — Loading... done — and the shell's next prompt appears right after it.

And print() with no arguments at all writes just end, which is the simplest way to emit a blank line:

>>> print("header")
header
>>> print()
 
>>> print("body")
body

To put each value on its own line, override sep:

>>> print("Mon", "Tue", "Wed", sep="\n")
Mon
Tue
Wed

4.3 Triple-quoted strings for multi-line output#

When the text you want to display already spans several lines — a poem, a SQL query, a template — capture it in a triple-quoted string and print it once:

>>> note = """Pick up groceries
... call the dentist
... water the plants"""
>>> print(note)
Pick up groceries
call the dentist
water the plants

Unlike \n, triple-quoted strings keep the line breaks exactly where you typed them, which makes them easier to read and edit.

5. Practical Recipes for Multi-Line Input#

5.1 Function and class definitions#

>>> class Greeter:
...     def __init__(self, name):
...         self.name = name
...     def run(self):
...         print(f"Hello, {self.name}!")
...
>>> Greeter("Ada").run()
Hello, Ada!

Keep the methods back to back like this while typing at the classic ... prompt: a blank line between them would end the class statement early, and the second method would then raise IndentationError as a stray top-level line. (Section 6.4 shows the same trap when pasting.)

5.2 Conditionals and loops#

>>> temps = [12.5, 30.0, 18.2, 22.0, 27.5]
>>> for t in temps:
...     if t >= 22:
...         print(f"{t}C: warm")
...     else:
...         print(f"{t}C: cool")
...
12.5C: cool
30.0C: warm
18.2C: cool
22.0C: warm
27.5C: warm

5.3 Comprehensions split across lines#

Wrapping a comprehension in brackets lets you give each clause its own line:

>>> warm = [
...     t
...     for t in temps
...     if t >= 22
... ]
>>> warm
[30.0, 22.0, 27.5]

5.4 Multi-line imports#

>>> from itertools import (
...     count,
...     cycle,
...     islice,
... )

A trailing comma after the last name is legal and makes future edits to the list safer.

6. Troubleshooting: When New Lines Do Not Work#

6.1 Your code runs immediately instead of continuing#

Symptom: you press Enter expecting a second line, but the code runs (usually with an error) at once. Cause: the first line was a complete simple statement, so the shell had no reason to wait. Fix: make the statement incomplete — end it with :, or open a bracket, or (rarely) end the line with a backslash.

The most frequent version of this is forgetting the colon. Modern Python reports it precisely:

>>> for color in ["red", "green"]
  File "<stdin>", line 1
    for color in ["red", "green"]
                                 ^
SyntaxError: expected ':'

Add the colon and the ... prompt appears as expected.

6.2 IndentationError on the body of a block#

Python requires the suite of a block to be indented. At the ... prompt, start the body with 4 spaces (one level), and keep every line of that block at the same level:

>>> user_is_admin = True
>>> if user_is_admin:
... print("Access granted")
  File "<stdin>", line 2
    print("Access granted")
    ^
IndentationError: expected an indented block after 'if' statement on line 1

(The wording of this message varies a little across Python versions; older releases say simply expected an indented block.)

If your terminal inserts a literal tab character, results vary across environments — prefer spaces. In Python 3.13+ the new shell's multi-line editing makes accidental misalignment much easier to spot and fix.

6.3 Stuck at ...: unclosed brackets or quotes#

If the ... prompt never ends, some bracket, parenthesis, brace, or quote is still open. Either complete it — or abort the input entirely:

  • Press Ctrl+C to discard the half-typed statement. The shell answers with KeyboardInterrupt and returns to >>>.
  • Press Ctrl+D at the ... prompt to signal end-of-input. If the statement is complete it runs; if a bracket is still open, Python 3.10+ reports SyntaxError: '[' was never closed.
>>> nums = [10, 20
...
KeyboardInterrupt
>>> print("back to business")
back to business

6.4 A blank line "eats" your block or your pasted code#

Two classic surprises:

  1. One-line compound statements still need the blank line. After for label in ["go", "stop"]: print(label) the shell shows ... because the statement ends with a colon. Type one more empty line and the loop runs; type anything else and you get SyntaxError: invalid syntax.
  2. Pasting code with blank lines. In the classic REPL, a blank line inside pasted code is treated as "block finished". A class or function pasted with the usual blank lines between methods is chopped into pieces, and the leftovers fail with IndentationError: unexpected indent. Workarounds: remove the blank lines before pasting, paste one method at a time, use an enhanced shell (section 7), or simply run the file. Python 3.13+ handles pasted multi-line code as a single block, so this problem is largely gone there (see section 8).

6.5 Ctrl+D in the wrong place#

Ctrl+D is only safe at the >>> prompt, where it exits the interpreter cleanly (on Unix; on Windows the equivalent is Ctrl+Z followed by Enter). At the ... prompt it ends the current input, which either runs a complete block or produces a syntax error. Whenever you want out, quit() and exit() work from any prompt.

7. Smarter Ways to Type Multi-Line Code#

The interactive shell is brilliant for short experiments, but it is not an editor. When your code outgrows a few lines, switch tactics:

7.1 Paste mode (Python 3.13+)#

The new shell's paste mode (press F3 to toggle) is designed for exactly this: it accepts large pasted blocks, including blank lines, and runs them as one unit when you leave the mode. If you are still on an older version, the safest route is to skip pasting entirely and use one of the options below.

7.2 exec() for a ready-made code string#

Store the code in a triple-quoted string and hand it to exec():

>>> block = """
... for name in ["Ann", "Bo"]:
...     print(name)
... """
>>> exec(block)
Ann
Bo

7.3 python -i your_file.py#

Write your multi-line code in a .py file with your favorite editor, run it, and land in the shell afterwards with everything already defined — the -i flag keeps the interpreter open after the script finishes:

$ python -i temps.py
>>> celsius_to_fahrenheit(25)
77.0

7.4 python -c with real newlines#

The shell you launch Python from can embed newlines. In Bash, the $'...' quoting form lets python -c run several lines at once:

$ python -c $'x = 3\nprint(x**5)'
243

7.5 Swap in a friendlier shell#

If you live in the interactive interpreter, these tools solve multi-line editing at the root:

  • IDLE — Python's bundled graphical shell and editor, a gentle next step for beginners.
  • IPython — the notebook-grade terminal shell with rich completion, %paste/%cpaste magics, and extensive history.
  • bpython and ptpython — two popular terminal replacements that add live highlighting, inline documentation, and more comfortable block editing.

Also note that frameworks sometimes ship their own entry point (for example, Django's manage.py shell). If multi-line input there behaves oddly, check which underlying REPL it is launching.

8. Python 3.13 to 3.15: A Much Friendlier REPL#

The default interactive shell received its biggest overhaul in years starting with Python 3.13 (October 2024), and it has kept improving since.

8.1 Python 3.13: multi-line editing, history, and F-keys#

According to the release notes, the new default shell (borrowed from PyPy) adds:

  • Multi-line editing with history preservation — edit whole blocks, and recall them in one keystroke.
  • Paste-friendly input — pasted code with blank lines is treated as one block instead of executing prematurely.
  • Paste mode on F3 — toggle a dedicated mode for pasting larger chunks of code.
  • Help browsing on F1 and history browsing on F2 (which skips prompts and output).
  • Color in prompts and tracebacks, controllable via PYTHON_COLORS, NO_COLOR, and FORCE_COLOR.
  • Bare commands — help, exit, and quit work without parentheses, while help() / exit() / quit() remain valid.

8.2 Python 3.14: syntax highlighting and import completion#

Python 3.14 made the shell feel like a small editor:

  • Live syntax highlighting of the code you type (can be disabled by PYTHON_BASIC_REPL or the no-color environment variables).
  • Import auto-completion — typing import co and pressing Tab suggests matching module names, and from concurrent import i suggests matching submodules. The experimental _colorize.set_theme() API customizes the color theme.

8.3 Python 3.15: smarter, colored completions#

Python 3.15.0 was released on 9 October 2026, and its shell refinements include:

  • Tab completions colored by object kind (based on fancycompleter; set PYTHON_BASIC_COMPLETER to fall back to the classic rlcompleter).
  • Attribute suggestions inside from ... import ... — standard-library modules are imported automatically so their attributes can be completed; for third-party modules the shell offers to import on a second Tab press.

8.4 Turning the new shell off#

Prefer the traditional behavior? Start the shell with PYTHON_BASIC_REPL=1 (environment variable) and you get the classic prompts and line-by-line handling back — useful for reproducing old tutorials or testing on legacy behavior.

9. Best Practices and Power-User Tips#

  1. Stick to 4-space indentation — the convention set by PEP 8 and the easiest way to avoid IndentationError at the ... prompt.
  2. Prefer parentheses to backslashes when wrapping a long line; reserve \ for cases where brackets cannot help. And never leave a space after that backslash.
  3. Keep shell experiments small. Try one loop or one function before building on it; the moment a block needs editing gymnastics, move it into a file and run python -i file.py.
  4. Use the history. The up arrow recalls previous input, and on most systems the shell persists it in .python_history in your user directory, so sessions build on each other.
  5. Lean on the _ variable. The shell saves the most recently evaluated value there, so you can chain calculations without retyping:
    >>> 128 * 2
    256
    >>> _ // 8
    32
  6. Read the docs from the prompt. help(print) opens documentation for any object without leaving the shell (or press F1 on Python 3.13+).
  7. Know your exits. quit() / exit(), or Ctrl+D on Unix (Ctrl+Z then Enter on Windows). Use Ctrl+C to cancel any statement you no longer want to finish.

10. Conclusion#

Getting to a new line in the Python shell is about teaching the REPL when a statement is unfinished. End a line with a colon to open a block, leave a bracket open to wrap a long expression, or fall back to a trailing backslash — then close the block with a blank line, closing quotes, or a closing bracket to run it. When what you actually need is a line break in output, use \n, an empty print(), the end/sep parameters, or a triple-quoted string.

The Python shell is also not standing still: since 3.13 it has offered true multi-line editing, whole-block history, and paste mode, with syntax highlighting in 3.14 and richer completion in 3.15. Whichever version you run, keep snippets small, move grown-up code to files, and keep this guide's troubleshooting checklist handy for the day a ... prompt refuses to let go.

11. References#