How it works
print("Score:", 95) receives two objects, not one joined string. The default sep is a space and the default end is a newline. A call with no arguments writes just the ending. Supply sep and end by name after the values.
The optional file argument selects a writable text stream; the default is sys.stdout. flush=True asks the stream to flush its buffer, which can help with progress messages. Output may otherwise be buffered by the terminal, editor or environment.
Printing is a side effect, not a way to return a calculation. print() returns None. A function should return a value when another part of your program needs to use that value.
Common mistakes and boundaries
Do not print passwords, tokens or private records when debugging. Use logging for application diagnostics that need levels and destinations, with the same care about sensitive data.
sep must be a string or None, and it only appears between arguments. It does not replace spaces inside a single argument.
Try it yourself
Print three dates with a custom separator, then build one progress line using end. Predict where the newlines appear before running the program. Finally inspect the return value of print().
Syntax
print(*values, sep=" ", end="\n")Examples
Basic Output
Printing simple values and multiple items in a single call.
print("Hello, World!")
print(42)
print("Score:", 95, "out of", 100)- Numbers are converted to text automatically, so separate arguments avoid manual string conversion.
- Expected output: Hello, World! 42 Score: 95 out of 100
Custom Separator
Using the 'sep' argument to control how multiple values are joined.
print("2026", "08", "08", sep="-") # 2026-08-08
print("a", "b", "c", sep=", ") # a, b, c- sep changes the text inserted between arguments. The date components remain strings, preserving leading zeroes.
- Expected output: 2026-08-08 a, b, c
Custom End Character
Using the 'end' argument to avoid the default newline, useful for progress indicators.
print("Loading", end="")
for _ in range(3):
print(".", end="")
print() # move to a new line afterward
# Output: Loading...- The first four calls suppress the newline. The final empty call writes it, completing the progress line.
- Expected output: Loading...
Printing with f-strings
Combining print() with formatted string literals for readable output.
name = "John"
score = 87
print(f"{name} scored {score}%")- The f-string constructs the message; print writes it and adds a newline.
- Expected output: John scored 87%
Best practices
- Use f-strings inside print() for readable, dynamic output rather than string concatenation with +
- Use print() for quick debugging, but prefer Python's logging module for anything in a real application that needs log levels or timestamps
- Remember print() always adds a newline by default - override with end='' when you need to build output incrementally
- Pass multiple arguments directly to print() instead of manually concatenating them with str()
- Avoid leaving stray debug print() statements in production code - remove or replace them with proper logging
Runtime & versions
Python interpreter. Feature availability depends on the language and runtime version used by your project; consult the official reference below.
Python language reference