Printing to stdout in Python

From NovaOrdis Knowledge Base
Revision as of 01:47, 20 June 2022 by Ovidiu (talk | contribs) (→‎Redirect to stderr)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

External

Internal

Overview

To send a string followed by new line to stdout:

print('something')

To avoid sending a new line at the end:

print('something', end='.')
print('something', end='')

print() strips quotes from strings, resolves escaped characters and displays the resulting content:

print('this is a\nmulti-line string')

results in:

this is a
multi-line string

print() add spaces between its arguments and a newline at the end:

print('A', 'B', 'C')

results in:

A B C

Redirect to stderr

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

pprint()

TODO IPy Print Nicely with pprint() Page 122.