Python3 | print () function

First, the introduction of knowledge:

1, print () function, a printout;

2、语法:print(*objects,sep='',end='\n',file=sys.stdout,flish=flase)。

  parameter:

objects - complex, it represents a plurality of output objects. A plurality of output objects, need, separated.

sep - interval for a plurality of objects, the default is a space.

end - the end of what used to be set. The default is a newline \ n-, End = '' does not wrap.

file - the file object to write.

flush - whether the output is cached usually depends on the file, but if the flush key parameter to True, the flow will be forced to refresh.

 

Second, the use of presentation:

. 1 ,
 Print ( ' ! Hello World ' )
 # Output: hello world! 
2 , Print ( ' Test01 ' ' test001 ' ' test0001 ' ) # outputs no need to partition the plurality of objects # Output: test01test001test0001
. 3 , Print ( ' Test01 ' , ' test001 ' , ' test0001 ' ) # output a plurality of objects required, separated # output: test01 test001 test0001
4 , Print( ' Test01 ' , ' test001 ' , ' test0001 ' , On Sep = ' sorted: ' ) # Output: Test01 Sort: test001 Sort: test0001
. 5 , Print ( ' . 1 ' , ' 2 ' , ' . 3 ' , On Sep = '\ n-') # On Sep =' \ n-'branch
# output:
1
2 . 3
. 6 , Print ( ' Python ' ) Print ( ' IS Good ' ) # outputs: Python IS Good If: End = ' ' Print ( ' Python ' , End = ' ' ) Print ( ' IS Good ' ) # outputs: Python IS Good # line
. 7 , for I in Range (. 5 ): Print ( ' cycle of the output: ' , I) # output newline is silent, i.e. end of the parameter \ n # Output: Loop output: 0 Output cycle: 1 Cyclic output: 2 Output cycle: 3 Cyclic output: 4
If: End = ' ' for I in Range (. 5 ): Print ( ' No Wrap output: ' , I, End = ' ' ) # Output: not wrap Output: 0 not wrap Output: 1 does not wrap output: output does not wrap 2: 3 does not wrap output: 4
. 8 , The default value of the parameter file sys.stdout, represents the system standard output. It can be made by varying the print parameters () function to a specific output file. F = Open (R & lt " F.: \ named text.txt in " , " W " ) # open the file for writing Print ( ' Test ' , File = F) # output to a file f.close () # file is closed after the operation, text.txt can see the test output to a file.
9 , flush parameter is used to control the output cache, primarily to refresh, the default False does not refresh, Ture refresh f = open(r'a.txt', 'w') print('python is good', file=f, flush=True) Under normal circumstances print the content f the pre-existing memory, when the object is closed when the output file contents to a.txt, when flush = True it will immediately refresh the contents stored in the a.txt

 

(- * -)Finish(- * -)

Guess you like

Origin www.cnblogs.com/ztz0/p/12517444.html