Driver FixRecommendedSound, Wi-Fi or graphics acting up? Check drivers firstFind missing or outdated drivers fast.Check DriversOctober DealsAmazon USOctober deal check: compare before you payAmazon US: current deals, useful picks and tech finds.Check DealsWindows FixRecommendedWindows errors stealing your time? Find the fix fastScan stability, cleanup and performance issues.Fix Now×
Skip to content
World desk3 min

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

Use n for a line break inside a Python string, or let print() move to the next line by default. See examples with variables, f-strings, end, and sep.

Free tools Windows power users keep installed

One-click scans. No signup required.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Use n inside a regular string to make a line break at a specific point, or rely on print()’s default ending to move to the next line after a value. For example, print(f"Hello, {name}nWelcome!") prints a greeting with the variable and welcome message on separate lines.

Put a line break inside a string

In a regular Python string, the escape sequence n represents a linefeed. Put it where the output should break:

print("First linenSecond line")

That prints:

First line
Second line

The backslash and lowercase n are typed in the source code; Python interprets them as one linefeed in the string. The Python 3.14.8 lexical analysis reference documents this escape sequence.

Print a new line after a variable

For a line break after a variable, a separate print() call is usually simplest. By default, each call ends with a newline:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
name = "Ada"
print(name)
print("Welcome")

The output is:

Ada
Welcome

To include the variable and a line break within one composed string, use an f-string:

name = "Ada"
message = f"Hello, {name}nWelcome!"
print(message)

This prints:

Hello, Ada
Welcome!

Expressions in f-string braces are substituted, and escape sequences in the f-string’s ordinary literal text are interpreted. See the Python 3.14.8 tutorial on input and output.

Choose between a string newline and print’s ending

These methods place the break in different places: n is part of the string, while print() adds its ending after the objects it prints. The built-in function’s end parameter defaults to 'n', so consecutive calls normally start on separate lines. The Python reference describes the behavior this way: “Print objects to the text stream file, separated by sep and followed by end.”

Method Where the break comes from Example
Newline in a string A linefeed inside the string, wherever n appears print("AnB")
Separate calls The default end='n' at the end of each call print(name); print(city)
Custom ending The value supplied to end after the printed objects print(name, end="")

The Python 3.14.8 built-in functions reference documents print(), including its sep and end parameters.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Control whether print adds a line break

Set end to change what print() appends after its output:

  • print(name, end="") suppresses the ending newline.
  • print(name, end="nn") adds two linefeeds after the value, leaving a blank line before subsequent output.

For example, this keeps the first two pieces of text on the same line:

print("Hello", end="")
print(" there")

The second call contributes its text and then its own default newline.

Add a blank line or put several values on separate lines

To leave one blank line between sections, either include a linefeed in the string and allow print() to add its usual ending, or set the ending explicitly:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
print("Section onen")
print("Section two")

# Alternatively:
print("Section one", end="nn")
print("Section two")

You can also use sep to place multiple objects on separate lines in a single call. It sets the separator between objects:

print(name, city, sep="n")
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Avoid these newline mistakes

  • Using a raw string: r"n" keeps the backslash and n as literal characters. Use "n" when you want an active line break.
  • Getting an extra break: print("Hellon") has a linefeed inside the string and also gets print()’s default ending. Use print("Hello", end="") if you want to omit the automatic ending.
  • Expecting braces to substitute a variable: print("{name}") prints the literal text {name}. Use print(f"{name}n") for an f-string, or print("{}n".format(name)).
  • Confusing printed output with a representation: print(value) displays a string’s contents; repr(value) shows a representation that can include quotes and escaped characters. The distinction is covered in the Python input and output tutorial.

Where print sends the output

By default, print() writes to sys.stdout. Its file= parameter can direct output to a file-like text stream instead. A terminal, IDE, or other output consumer determines how control characters appear on screen; the Python syntax specifies the linefeed, not the rendering behavior of every display.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

Leave a Reply

Your email address will not be published. Required fields are marked *

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

More from the Wire

  1. World desk4 min
    How to Spot an AI Voice Scam Before Sending MoneyDon’t rely on how a caller sounds. Pause, call back through a known number, and verify the emergency with another trusted person before sending money.
  2. Mountain View desk4 min
    Google’s SynthID Detector: How to Check AI-Generated Images, Video and AudioGoogle’s SynthID Detector looks for an embedded watermark in supported images, video and audio. Here is what its results do—and do not—show.
  3. Redmond desk20 min
    How to create a link to File or Folder in Windows 11Windows 11 gives you several ways to point to a file or folder without moving or duplicating it. You can create a desktop shortcut,…
Recommended PC Tool
Recommended PC Tool
Windows Errors? Fix Them Before They SpreadFree repair scan
Crashes, No Sound, or Screen Glitches?Free driver scan

Two free Windows tools

One Free Minute Could Fix That PC

Before you go - each of these free tools takes about a minute and tackles what quietly slows a Windows PC down.

Special offer. View Outbyte info, uninstall instructions, EULA, and Privacy Policy.