Differences
This shows you the differences between two versions of the page.
Both sides previous revision
Previous revision
|
|
python3:output [2018/08/15 16:26] jguerin Cut out concatenation and casting examples in favor of a description. |
python3:output [2018/08/15 16:33] (current) jguerin Added byte count output to shell examples, removed and condensed associated descriptions. |
| |
===== Advanced Output ===== | ===== Advanced Output ===== |
| |
''print()'' is a wrapper around Python's ''write()''. In some instances, ''write()'' may outperform ''print()''. | |
| |
''write()'' requires a single ''str'' argument. ''write()'' does not perform concatenation, and does //not// automatically insert a ''\n'' at the end of your output. ''write()'' returns the number of characters written to the underlying stream. This is hidden in competition environments, but it will appear if testing in the [[competitive_programming:python_interpreter|interactive interpreter]]. | |
| |
<code python> | <code python> |
>>> from sys import * | >>> from sys import * |
>>> stdout.write('\n') # '\n' | >>> stdout.write('\n') |
| |
| 1 |
</code> | </code> |
| |
| ''stdout.write()'' returns the number of characters written to the underlying stream, but only prints the information in the context of the [[competitive_programming:python_interpreter|interactive interpreter]].((This information is suppressed when ''stdout.write()'' is used in the context of a ''.py'' file, and hence requires no special handling in contests.)) |
| |
<code python> | <code python> |
>>> from sys import * | >>> from sys import * |
>>> stdout.write("Hello World!\n") # "Hello World!\n" | >>> stdout.write("Hello World!\n") # "Hello World!\n" |
| Hello World! |
| 13 |
</code> | </code> |
| |