Post

print(): showing output in Python

How print() works in Python 3: printing several values, the sep and end arguments, printing to stderr, and the common mistake of printing None.

print() is the most used function in Python. It writes text to the screen, usually for debugging or to show a result.

Every code example here was run with Python 3.13, and the behavior was checked against the official print() docs.

Printing one value or several

print() accepts any number of values, separated by commas. It converts each one to text and puts a space between them:

print("Hello")
print("a", "b", "c")
Hello
a b c

Each print() call ends with a newline, so the next call starts on a new line. With no arguments, print() prints just an empty line. To mix text and variables in one string, use an f-string.

sep and end

Two keyword arguments control the separator and the ending:

  • sep goes between the values (default: a space).
  • end goes after the last value (default: \n, a newline).
print("a", "b", "c", sep="-")
print("no newline", end=" ")
print("continues here")
print()
a-b-c
no newline continues here

The docs say sep, end, file and flush “must be given as keyword arguments”, so print("a", "b", "-") is not a separator. It’s a third value, and it prints a b -.

Where the output goes

By default print() writes to standard output. The file argument sends it somewhere else. Errors and warnings usually go to standard error (sys.stderr), so they can be separated from normal output:

import sys

print("something went wrong", file=sys.stderr)

In a terminal both streams look the same. The difference matters when you redirect output to a file.

Common mistake: print returns None

print() shows the value, but it doesn’t return it. If you assign its result, you store None:

x = print("hi")
print(x)
hi
None

If you want the value to stay in a variable, assign it first and print the variable.

What’s next

Next: variables and types.