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
input()
Reads a line from sys.stdin, strips the trailing newline, and returns it as a string. Optionally writes prompt to stdout first.
open()
Opens a file and returns a file object. Default mode 'r' is text read; use 'rb'/'wb' for binary.
str()
Returns a str version of an object. With bytes/bytearray, decodes using encoding.