← Python lessons

Python print() sep and end Parameters

Part of a free Python course — sign up to save your progress and get AI hints.Sign up free

The sep and end options of print() change what goes between values and what goes after them.

Read Printing Output first.

Change the separator with sep

By default sep is one space. Give it any string instead.

print("2026", "11", "07", sep="-")
print("a", "b", "c", sep="")

This prints 2026-11-07, then abc. sep only goes between values, never before the first or after the last.

Change the line ending with end

By default end is a new line, "\n". Change it to keep the next print on the same line.

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

All three calls print one line: Loading... done.

Use sep and end together

Both options can go in one call. They must come after the values, written as sep= and end=.

for n in [1, 2, 3]:
    print(n, n * n, sep=":", end="  ")
print()

This prints 1:1 2:4 3:9. The empty print() at the end finishes the line.

The difference to remember: sep goes between the values of one call, end goes after the last value. Use end when several calls should build one line.

Note: sep and end must be strings. print(1, 2, sep=0) raises TypeError. When the line needs labels and spacing mixed together, an f-string is often clearer than sep.

try:
    print(1, 2, sep=0)
except TypeError as error:
    print("TypeError:", error)

See also: String Formatting, Lists.

Your turn

Print the items in parts on one line joined by /, then print end on the next line. Use sep for the first line.

parts = ["home", "ada", "games"]
# add two prints: the three parts joined with sep="/", then the word end

Expected output

home/ada/games
end