How to Print a New Line in Python (Including After a Variable)

Python’s print() ends every call with a new line, so printing a new line in Python usually means doing nothing extra. Call print() on its own for a blank line, or put \n inside the text:

print("First line")
print()                      # blank line
print("Line one\nLine two")

The details trip people up, though, starting with print("\n") giving two line breaks. Every output here is a real run on Python 3.14.7.

Diagram of how Python print joins values with sep and adds end, and why printing a newline gives two line breaks
print() glues the values together with sep and adds end, which is a new line by default.

Print a new line in Python with print()

Here’s the basic behavior, with nothing but print():

print("First line")
print("Second line")
print()                        # an empty print() is a blank line
print("After a blank line")
print("Line one\nLine two")    # \n inside the string

Output:

First line
Second line

After a blank line
Line one
Line two

Each print() call lands on its own line because it ends with a new line automatically. A bare print() with no arguments prints just that new line, which shows up as a blank line.

Inside a string, \n starts a new line wherever you put it. That’s how one print() call produces two lines of output.

The \n character itself, and everything you can do with it in strings, is covered in the guide to the Python newline character.

How to break a line in Python (output versus code)

“Break a line” can mean two different things, and people mix them up. One is a line break in what gets printed; the other is splitting a long line of code:

print("This message is long enough that I split it "
      "over two lines of code, but it prints on one line.")
print()

print("This one has a real line break\n"
      "because the first part ends with \\n.")

Output:

This message is long enough that I split it over two lines of code, but it prints on one line.

This one has a real line break
because the first part ends with \n.

Two strings side by side inside the parentheses are joined into one, with no line break, so the first message prints on a single line. Only the \n in the second call breaks the output.

I split long print() calls this way all the time. Wrapping the pieces in parentheses keeps the code readable without changing what’s printed.

Print a new line after a variable in Python

This is the question most people land here with. The short answer: you usually don’t need to do anything, because print() already moves to the next line.

name = "Ava"
city = "Austin"
total = 42.5

print(name)                    # print() already ends the line
print(city)
print()

print(f"Name: {name}\nCity: {city}\nTotal: ${total:.2f}")
print()

print(name, city, total, sep="\n")    # one value per line

Output:

Ava
Austin

Name: Ava
City: Austin
Total: $42.50

Ava
Austin
42.5
Command Prompt showing Python printing variables each on a new line with print, an f-string and sep
Three ways to put variables on separate lines: separate calls, \n in an f-string, and sep="\n".

Separate print() calls are the simplest. An f-string with \n between the values builds the whole block in one call, which is handy for a receipt or a summary.

sep="\n" is the neat one for several variables. It tells print() to put a new line between the values instead of a space.

Mixing text and variables on one line is a topic of its own, covered in printing a string and a variable.

Print a new line inside an f-string

\n works anywhere in the text part of an f-string. Inside the curly braces it’s a newer feature:

import sys

states = ["California", "Texas", "New York"]
total = 3

print(f"States:\n{'\n'.join(states)}\nTotal: {total}")
print()

nl = "\n"                                  # works on every Python 3 version
print(f"States:{nl}{nl.join(states)}{nl}Total: {total}")
print()
print("ran on", sys.version.split()[0])

Output:

States:
California
Texas
New York
Total: 3

States:
California
Texas
New York
Total: 3

ran on 3.14.7

Putting '\n'.join(...) inside the braces works on Python 3.12 and later. On 3.11 and older it’s a SyntaxError, so if your code has to run there, store the new line in a variable first, like nl.

I still use the variable version in code that other people run, since you can’t always control which Python they have installed.

Why print("\n") gives you two new lines

This is the most common surprise. You ask for one new line and get two:

import io, contextlib

print("Before")
print("\n")                    # meant as one new line
print("After")
print()

buffer = io.StringIO()
with contextlib.redirect_stdout(buffer):
    print("\n")
print("print('\\n') actually wrote:", repr(buffer.getvalue()))

name = "Ava"
buffer = io.StringIO()
with contextlib.redirect_stdout(buffer):
    print(f"{name}\n")
print("print(f'{name}\\n') wrote:  ", repr(buffer.getvalue()))

Output:

Before


After

print('\n') actually wrote: '\n\n'
print(f'{name}\n') wrote:   'Ava\n\n'
Command Prompt showing Python print with a newline character writing two line breaks instead of one
print("\n") writes your \n plus its own, so there are two blank lines between Before and After.

print() adds its own \n after whatever you pass. So print("\n") writes your line break and then another one, and the capture shows '\n\n'.

The same thing happens when you end an f-string with \n. print(f"{name}\n") leaves a blank line after the name, which may or may not be what you wanted.

For one blank line, use a bare print(). There’s more on blank lines in skipping a line in Python.

Print each list item on a new line

Printing a list shows the brackets and commas. To get one item per line instead, there are three good options:

states = ["California", "Texas", "New York"]

print(*states, sep="\n")
print()
print("\n".join(states))
print()
for number, state in enumerate(states, start=1):
    print(f"{number}. {state}")
print()

prices = [19.99, 5, 42.5]
print(*prices, sep="\n")       # numbers are fine here
try:
    print("\n".join(prices))
except TypeError as err:
    print("TypeError:", err)

Output:

California
Texas
New York

California
Texas
New York

1. California
2. Texas
3. New York

19.99
5
42.5
TypeError: sequence item 0: expected str instance, float found
Command Prompt showing Python printing each list item on a new line with sep, join and a loop
print(*items, sep="\n") works for any values; join() needs strings.

print(*states, sep="\n") unpacks the list into separate arguments and puts a new line between them. It’s my go-to, because it works with numbers too.

"\n".join() builds one string first, which is useful when you want to store or return the text. It only accepts strings, which is why the price list raised a TypeError.

A loop is the choice when each line needs extra formatting, like the numbered list. Printing a list without brackets covers more layouts.

Control line endings with end and sep in print()

Two keyword arguments decide what print() puts between values and after them, and the end parameter is the one you’ll use most:

print("Loading", end="")
print("...", end="")
print(" done")                 # the default end is "\n"
print()

print("a", "b", "c")           # the default sep is a space
print("a", "b", "c", sep=", ")
print("a", "b", "c", sep="\n")
print()

print("Two blank lines follow", end="\n\n\n")
print("next")

try:
    print("x", end=5)
except TypeError as err:
    print("TypeError:", err)

Output:

Loading... done

a b c
a, b, c
a
b
c

Two blank lines follow


next
TypeError: end must be None or a string, not int
Command Prompt showing the Python print end and sep parameters and the TypeError when end is not a string
end replaces the final new line; sep replaces the space between values.

end is what comes after the output, and it’s "\n" by default. Setting end="" keeps the next print() on the same line, which is how the loading line was built in three calls.

sep goes between the values. The default is a single space, and it can be any string, including a comma or a new line.

Both must be strings. end=5 raises TypeError: end must be None or a string, not int, while None just means the default.

Staying on one line is its own topic, with progress bars and more, in printing on the same line in Python.

Is there a println in Python?

No. If you’re coming from Java, Python’s print() already behaves like println:

try:
    println("Hello")
except NameError as err:
    print("NameError:", err)

print("Hello")                 # Java: System.out.println("Hello")
print("Hello", end="")         # Java: System.out.print("Hello")
print()                        # Java: System.out.println()

Output:

NameError: name 'println' is not defined
Hello
Hello

In a normal traceback, Python even suggests the fix: NameError: name 'println' is not defined. Did you mean: 'print'?

JavaPython
System.out.println("Hi")print("Hi")
System.out.print("Hi")print("Hi", end="")
System.out.println()print()
System.out.printf("%.2f%n", x)print(f"{x:.2f}")

The last row is formatting rather than new lines, and printing two decimal places goes into it properly.

Print \n literally instead of a new line

Sometimes you want the characters \n on screen, for a message or a help text. Escape the backslash or use a raw string:

print("Line one\nLine two")         # a real line break
print("Line one\\nLine two")        # doubled backslash: prints \n
print(r"Line one\nLine two")        # raw string: prints \n too
print(repr("Line one\nLine two"))   # repr shows the escape

Output:

Line one
Line two
Line one\nLine two
Line one\nLine two
'Line one\nLine two'

"\\n" is a backslash followed by an n, so it prints as \n. A raw string, r"...", treats every backslash literally.

repr() is the debugging version. It shows exactly which escapes are in a string, which is the quickest way to find a stray \n or \r.

Tabs, quotes and the other escapes are listed in the Python escape sequences guide.

Print a separator line between sections of output

A line of dashes or equals signs makes console output much easier to scan. String repetition does it in one go:

width = 40
months = (("July", 125000), ("August", 98000), ("September", 110500))

print("=" * width)
print(f"{'Monthly sales report, 2026':^{width}}")
print("=" * width)
for month, sales in months:
    print(f"{month:<12}${sales:>12,}")
print("-" * width)
print(f"{'Total':<12}${sum(s for _, s in months):>12,}")

Output:

========================================
       Monthly sales report, 2026       
========================================
July        $     125,000
August      $      98,000
September   $     110,500
----------------------------------------
Total       $     333,500

"=" * width repeats the character, and the format specs line the columns up underneath. :^{width} centers the title, and :>12, right-aligns the numbers with thousands separators.

Keeping the width in one variable means you change it in one place and every line still matches. I do this for any script whose output someone else has to read, like a nightly report.

New lines in redirected output: print(), sys.stdout.write() and os.linesep

On screen, \n just works. When you redirect output to a file on Windows, the bytes tell a different story:

import subprocess, sys

snippets = ("print('a')",
            "import os; print('a', end=os.linesep)",
            "import sys; sys.stdout.write('a\\n')")

for code in snippets:
    with open("out.txt", "wb") as f:              # stdout goes to a file
        subprocess.run([sys.executable, "-c", code], stdout=f)
    print(f"{code:<40} -> {open('out.txt', 'rb').read()}")

Output:

print('a')                               -> b'a\r\n'
import os; print('a', end=os.linesep)    -> b'a\r\r\n'
import sys; sys.stdout.write('a\n')      -> b'a\r\n'
Command Prompt showing the bytes Python print writes when output is redirected to a file on Windows with os.linesep
end=os.linesep writes \r\r\n when output goes to a file on Windows.

Plain print() writes \r\n, the correct Windows line ending, because Python translates \n for you. sys.stdout.write() does the same, but it never adds a new line on its own.

os.linesep is the trap. You’ll see it recommended for new lines in print, but it’s already \r\n, and Python translates the \n part again, so the file gets \r\r\n.

On macOS and Linux, os.linesep is a plain new line, so the bug stays hidden there. Just use the default end and let Python handle it.

New lines with python -c

One more place where new lines behave differently is a one-line command:

import subprocess, sys

for code in ("print('a\\nb')", "import sys\\nprint(1)", "import sys; print(1)"):
    r = subprocess.run([sys.executable, "-c", code], capture_output=True, text=True)
    result = r.stdout.strip().replace("\n", " | ") or r.stderr.strip().splitlines()[-1]
    print(f'python -c "{code}"'.ljust(38), "->", result)

Output:

python -c "print('a\nb')"              -> a | b
python -c "import sys\nprint(1)"       -> SyntaxError: unexpected character after line continuation character
python -c "import sys; print(1)"       -> 1

Inside a string that print() receives, \n works as usual. As a separator between statements it doesn’t, and Python raises a SyntaxError. Use semicolons to put several statements in one -c command.

A few more printing guides you might like:

Frequently asked questions

How do I print a new line in Python?

Call print() with no arguments for a blank line, or put \n inside the text: print("Line one\nLine two"). Every print() call already ends with a new line.

How do I print a new line after a variable?

print(name) already moves to the next line. For several variables, use print(a, b, sep="\n") or an f-string with \n between the values.

Why does print(“\n”) print two blank lines?

Because print() adds its own \n after your text. Use a bare print() for a single blank line.

How do I print each list item on a new line?

Use print(*items, sep="\n"). It works with any values, while "\n".join(items) needs strings.

Is there a println in Python?

No. print() already ends with a new line like Java’s println. Use print(text, end="") for Java’s print.

How do I print \n without a new line?

Escape the backslash, print("\\n"), or use a raw string, print(r"\n").

What does end mean in print()?

It’s the text added after the output, "\n" by default. end="" keeps the next print on the same line. The full signature is in the Python print() documentation.