Python 3 reference · Built-in Functions

Python print() Function

Write values to standard output (or a file), separated by spaces and followed by a newline. Both are configurable.

Python 3 Since 3.0

Syntax

print(*objects, sep=" ", end="\n", file=None, flush=False)

Parameters

ParameterDescription
*objects optional Any number of values; each is converted with str().
sep optional Text between values. Default: " "
end optional Text after the last value. Default: "\n"
file optional Where to write: sys.stdout by default, or any object with write().
flush optional Flush the output immediately. Default: False

Return value

None.

Examples

Separators and line endingsTry it yourself
print("Hello", "world", 2026)
print("a", "b", "c", sep="-")
print("no newline", end=" | ")
print("next")

Output

Hello world 2026
a-b-c
no newline | next
Printing formatted valuesTry it yourself
name, score = "Ada", 95.456
print(f"{name} scored {score:.1f}")
print("Total:", 3 + 4)

Output

Ada scored 95.5
Total: 7
Errors and unpacking a listTry it yourself
import sys
print("something went wrong", file=sys.stderr)
rows = [["id", "name"], [1, "Ada"]]
for row in rows:
    print(*row, sep="\t")

Output

something went wrong
id	name
1	Ada

Good to know

  • print(*items) prints a list's items separated by spaces instead of the list itself.
  • Use flush=True for progress messages that must appear immediately.

Version history

VersionChange
Python 3.0Added
Python 3.3Added the flush parameter.