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 DealsSlow PC?RecommendedPC slow today? Run a repair scan before it gets worseResolve common Windows issues and optimize system performance.Scan Now×
Skip to content
World desk2 min

How to Print on the Same Line in Python

Set print()’s end argument to a space or an empty string to keep consecutive Python output on the same line.
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Set the end argument of print() to control what follows the text. Use end=' ' for a space between calls, or end='' to join their output directly.

print('Hello', end=' ')
print('world')
# Hello world

Use end to keep consecutive calls on one line

By default, print() ends its output with a newline (n), so the next call starts on a new line. Set end to a different string to change that behavior. The built-in function’s signature is print(*objects, sep=' ', end='n', file=None, flush=False). Python’s built-in functions reference describes the output as objects separated by sep and followed by end.

As an Amazon Associate I earn from qualifying purchases.

Join output without a gap

print('Loading', end='')
print('...')
# Loading...

Because the first call adds no trailing character, the second string begins immediately after Loading.

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

Keep a visible space between outputs

print('Hello', end=' ')
print('world')
# Hello world

Use a space when the output consists of words or values that would otherwise run together.

Know when to use sep instead

sep separates multiple objects passed to a single print() call. end is added after all the objects in that call. Both are keyword arguments.

print('Name:', 'Ada', 'Lovelace', sep=' ', end='!n')
# Name: Ada Lovelace!

Changing sep will not stop separate calls from starting on new lines. To control the ending of each call, change end.

Rewrite a status line in a terminal

For terminal output that should update in place, use a carriage return (r) as the ending. It returns the cursor to the start of the current line:

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

for percent in range(0, 101, 10):
    print(f'Progress: {percent}%', end='r', flush=True)
    time.sleep(0.1)
print()  # finish the progress line

flush=True asks Python to flush the output stream promptly; it does not remove a newline. Buffering depends on the stream: interactive standard output is line-buffered, while non-interactive standard output is block-buffered. The Python sys reference documents standard output. Carriage-return updates are intended for terminal-style output; redirected output and logs may show each update instead of replacing a single visible line. If a new status is shorter than the previous one, leftover characters may remain on screen.

Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Use sys.stdout.write() for direct text output

For direct writes to standard output, use the write() method. Unlike print(), it does not automatically insert separators or an ending string, so include spaces or newlines yourself when needed.

import sys

sys.stdout.write('Hello')
sys.stdout.write(' worldn')

The Python tutorial’s file I/O section explains the write() method and standard text output.

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.

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.

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.