DriversRecommendedOutdated drivers can make a good PC feel brokenScan driver issues before chasing fixes manually.Scan NowOctober 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 desk2 min

How to Use `sep` and `end` in Python’s `print()` Function

Use sep to change what appears between objects passed to Python’s print(); use end to change what follows the final object.
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

sep sets what goes between the objects passed to print(); end sets what goes after the last object. By default, Python separates objects with a space and ends each call with a newline.

What do sep and end do?

Python’s built-in function has the signature print(*objects, sep=' ', end='n', file=None, flush=False). It converts each object to text as str() does, joins the results with sep, then writes end after them. See the Python 3.13.16 built-in function reference.

As an Amazon Associate I earn from qualifying purchases.

Argument What it controls Default
sep Text between separate objects in the call A single space
end Text written after the final object A newline (n)

How do you change the separator?

Pass sep as a keyword argument to replace the default space between objects:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
print("red", "green", "blue")
# red green blue

print("red", "green", "blue", sep=", ")
# red, green, blue

The separator applies only between distinct objects passed to the call. It does not edit the contents of a string:

print("a", "b", sep="/")
# a/b

print("a b", sep="/")
# a b

In the second call, "a b" is one object, so there is no boundary for sep to replace.

How do you change what comes after the output?

By default, a call ends with a newline, so the next printed text starts on a new line. Set end to another string to replace that newline:

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

Setting end="" adds no text after the output, so the next call continues immediately:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
print("Hello", end="")
print(" there")
# Hello there

end changes only the ending; it does not remove the text printed by the call.

Can sep or end be None?

Yes. Either argument can be None, which tells print() to use that argument’s default: a space for sep or a newline for end. Otherwise, both arguments must be strings.

What happens when you call print() with no objects?

With no objects, print() writes only its end value. Because the default ending is a newline, an empty print() call normally creates a blank line. If you supply a different ending, it writes that string instead.

Where does print() write?

Unless you pass a file argument, print() writes to sys.stdout. A supplied file object must have a write(string) method; print() writes text, not binary data. The optional flush=True argument forces the stream to flush; otherwise, buffering is generally determined by the stream.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

When should you use a different formatting method?

sep and end control the boundaries around printed objects, not the construction of complex text. For formatted text with values embedded in a sentence, an f-string is often clearer. Python’s informal introduction and input and output tutorial explain string formatting and output behavior. Special characters such as n in printed text are rendered as line breaks.

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
Outdated Drivers Are Slowing You DownFree scan - exact matches
PC Slower Than It Used to Be?Free scan - under a minute

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.