--- --- restore content begins
python Sao operation --- Print function usage
In Python, print
you can print all the variable data, including custom type.
In 3.x is a built-in functions, and has more features.
Parameter options
It can be used help(print)
to view print
explain the function parameters.
print(...) print(value, ..., sep=' ', end='\n', file=sys.stdout, flush=False) Prints the values to a stream, or to sys.stdout by default. Optional keyword arguments: file: a file-like object (stream); defaults to the current sys.stdout. sep: string inserted between values, default a space. end: string appended after the last value, default a newline. flush: whether to forcibly flush the stream.
- value: the value of the print can be a plurality of
- file: the output stream, default
sys.stdout
- sep: separators between the plurality of values
- end: end, default is a newline
\n
- flush: whether to force a refresh to the output stream, default NO
1. Type and numeric strings
>>> print(1) 1 >>> print("Hello World") Hello World
2. Output redirection
By default, print
the function will be to print out the contents of the standard output stream (i.e. sys.stdout), can be customized by the file output stream parameters.
At this time, there will be no standard output, but the corresponding file already has content.
We can also output to the error output stream, for example:
import sys print('hello world!', file=sys.stderr)
3. separated
>>>print("hello", "world", "hello", "world", "hello", "world", sep="-") hello-world-hello-world-hello-world
4. Terminator
The default terminator is the line number, end
parameters can be modified.
>>>for i in range(10): print(">") >>>> > > > > > > > > >
>>>for i in range(10): print(">",end="") >>>>>>>>>>>>>
5. Wrap
During operation Shi print, print data in the buffer, the buffer is flushed data to the console display
Wherein the cache flush data to the console of the three conditions, one can meet to refresh the display console
1. there is a line break,
2.flush as Ture
3. Run the code or the end of the buffer is full