io

print()

Writes the given objects to a text stream, converting each with str() and joining with sep. Adds end (newline by default) after the last object.

print(*objects, sep=' ', end='\n', file=sys.stdout, flush=False)

Parameters

Parameter Purpose
sep String between objects (default single space)
end String appended after last object (default '\n')
file Output stream (default sys.stdout)
flush Force flush the stream when True

Examples

print('a', 'b', sep='-')

Prints 'a-b'

print('loading', end='...'); print('done')

Prints 'loading...done'

print('err', file=sys.stderr)

Writes to stderr

print('live', flush=True)

Bypasses buffering (useful in pipes)

Gotcha

print() is a function in Python 3 — parentheses required. Buffered by default in non-tty output; pass flush=True or set PYTHONUNBUFFERED=1.

Related built-ins

← All Python built-ins