Printing to stdout in Python

From NovaOrdis Knowledge Base
Jump to navigation Jump to search

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

Redirect to stderr

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