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
| Parameter | Description |
|---|---|
*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
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
name, score = "Ada", 95.456
print(f"{name} scored {score:.1f}")
print("Total:", 3 + 4)
Output
Ada scored 95.5 Total: 7
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=Truefor progress messages that must appear immediately.
Version history
| Version | Change |
|---|---|
| Python 3.0 | Added |
| Python 3.3 | Added the flush parameter. |
Related
input()· Read a line of text typed by the user, after printing an optional prompt. The result is always a string.format()· Format a single value with a format spec, such as format(3.14159, '.2f') giving '3.14'. The same mini-language as f-strings.repr()· Return the developer-friendly string representation of an object, often valid Python code that recreates the value.str()· Convert a value to its readable text form, or decode bytes into a string. Strings are immutable sequences of characters.- Python Syntax · tutorial
- Python String Formatting · tutorial