User Tools

Site Tools


python3:output

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

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.
Line 31: Line 31:
  
 ===== 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>
  
python3/output.1534368403.txt.gz · Last modified: 2018/08/15 16:26 by jguerin