Python Output
Master the print() function to display text, numbers, multiple values, custom separators, and line endings.
After completing this chapter, you will be able to:
- Display text and numbers using Python's print() function.
- Print multiple values inside a single print() call.
- Customize spacing between values using the sep parameter.
- Control line endings using the end parameter.
The print() Function
Whenever you want your program to show information on the screen, you call print(). Without print(), Python computes values silently in memory without showing them.
print(value1, value2, ..., sep=" ", end="\n")By default, print() separates multiple values with one space and ends with a new line.
Printing Text and Numbers
- Text (strings) must be enclosed in single quotes
'...'or double quotes"...". - Numbers are written directly without quotes. You can also print math expressions directly!
Strings use quotes; numbers and math expressions do not.
print("Python Output Lesson")
print(2026)
print(15 + 25)Expected Output
Python Output Lesson 2026 40
Single vs. double quotes
Both "Hello" and 'Hello' work identically in Python. Choose one style and stay consistent—or use double quotes when your text contains an apostrophe like "It's sunny".
Printing Multiple Values
You can pass several values to print() separated by commas ,. Python automatically inserts a single space between each value and converts numbers into printable text for you.
Commas let you mix strings and numbers cleanly in one line.
print("Score:", 95, "out of", 100)
print("Total cost:", 3 * 12)Expected Output
Score: 95 out of 100 Total cost: 36
Custom Separators with sep
By default, print() puts a space " " between comma-separated values. You can change that separator by passing sep="..." at the end of your print() call.
Use sep to join values with hyphens, slashes, or no space at all.
print("2026", "11", "12", sep="-")
print("Python", "is", "clear", sep=" | ")
print("A", "B", "C", sep="")Expected Output
2026-11-12 Python | is | clear ABC
Controlling Line Endings with end
Normally, every print() statement ends by moving to a new line (\n). If you want the next print() to continue on the same line, set end="...".
Setting end=' ' prints a space instead of starting a new line.
print("Loading", end="... ")
print("Ready!")
print("Count:", end=" ")
print(1, 2, 3, sep=", ")Expected Output
Loading... Ready! Count: 1, 2, 3
Keyword options like sep and end must always appear after the values you want to print. Putting sep first raises a SyntaxError.
print(sep="-", "2026", "11", "12")print("2026", "11", "12", sep="-")Quick Check
What will this code print?
print("Hi", "there", sep="-", end="!")print("Welcome")Chapter Summary
print()shows text, numbers, and expressions on the screen.- Passing comma-separated items prints them on one line with a space in between.
sep="..."changes the separator placed between items.end="..."changes what appears at the end of theprint()call instead of a newline.