Python Notes and Examples
← prev | next →     Top-level ToC     /stdin-stdout-stderr.html     (printable version)

To get input from the user on stdin:

s = input("Today's comment?: ")
# `s` won't have a newline at the end.

Printing to stdout:

print('hey')                   # With newline.
print('hey', end='')           # No newline.
print('a', 'b', 'c', sep=':')  # Prints "a:b:c".
print('bye', flush=True)       # Flush the stream.

Print to stderr:

import sys
print('hi', file=sys.stderr)

See also help(print).