Printing to stdout in Python: Difference between revisions
Jump to navigation
Jump to search
Line 15: | Line 15: | ||
</syntaxhighlight> | </syntaxhighlight> | ||
<code>print()</code> strips [[Python_Language_String#Quotes|quotes]] from strings, resolves escaped characters and displays the resulting content: | <code>print()</code> strips [[Python_Language_String#Quotes|quotes]] from strings, resolves [[Python_Language_String#Escaped_Characters|escaped characters]] and displays the resulting content: | ||
<syntaxhighlight lang='py'> | <syntaxhighlight lang='py'> | ||
print('this is a\nmulti-line string') | print('this is a\nmulti-line string') |
Revision as of 19:34, 18 June 2022
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)