Printing with sep and end
15 min · Beginner
Need help? Ask a tutor on WhatsApp (opens in a new tab)The print() function is Python's most versatile debugging and display tool. Mastering sep and end eliminates ugly manual string concatenation.
Printing multiple items
Pass several comma-separated values to print(). Python turns each one into text and puts a space between them.
day = 1month = "November"year = 2026print(day, month, year)Example 1 · One line order summary
order_id = 1042amount = 2599.5print("Order", order_id, "total", amount)print("Status:", "Packed")Order 1042 total 2599.5 Status: Packed
What this code does
- Each comma-separated value becomes text, then print puts a space between them.
- The number
1042and the float2599.5need no conversion. - The second print starts on a new line, because
endis still its default.
The console shows 1 November 2026. You did not need str() or +, so numbers and text mix freely.
Custom separators with sep
Separator is the text print() puts between the values it prints. It is one space unless you set sep.
A space is not always what you want between values. The sep argument changes it.
print("2026", "11", "02", sep="-")print("user", "server", "db", sep=" > ")Example 2 · Dates and paths with sep
print(2026, 11, 3, sep="-")print("home", "user", "reports", sep="/")2026-11-3 home/user/reports
What this code does
sep="-"replaces the default space between the three numbers.- The same argument builds a path-like text with
/.
The output is 2026-11-02 and user > server > db. Setting sep="" joins the values with nothing between them.
Controlling line endings with end
End string is the text print() writes after its last value. It is a new line ("\n") unless you set end.
Each print() normally finishes with a new line. The end argument changes what is written after the last value, so the next print continues on the same line.
print("Loading", end="...")print("Done!")Example 3 · Progress on one line
print("Packing", end=" ... ")print("Shipping", end=" ... ")print("Done")Packing ... Shipping ... Done
What this code does
- The first two prints end with
...instead of a new line. - The last print uses the default end, so the cursor moves to the next line.
The console shows Loading...Done! on one line, because the first print ended with ... instead of a new line.
Newlines and tabs inside text
Escape sequence is a backslash plus a letter inside a string that stands for one special character, such as \n for a new line.
Some characters cannot be typed inside quotes directly. A backslash starts an escape: \n is a new line and \t is a tab.
print("Item\tQty")print("Pen\t4\nBook\t2")print()Example 4 · A small table with tab and newline
print("Item\tQty\nPen\t4\nBook\t2")Item Qty Pen 4 Book 2
What this code does
- One print call writes three lines, because
\nends a line inside the text. \tpushes the quantity to the next tab stop.
Each \t jumps to the next tab stop, so the columns line up. A print() with no values writes only a blank line.
Next step
Check your understanding
9 quick questions