原英文帮助文档:
print
(*objects, sep=‘ ‘, end=‘\n‘, file=sys.stdout, flush=False)
Print objects to the text stream file, separated by sep and followed by end. sep, end, file and flush, if present, must be given as keyword arguments.
All non-keyword arguments are converted to strings like str()
does and written to the stream, separated by sep and followed by end. Both sep and end must be strings; they can also be None
, which means to use the default values. If no objects are given, print()
will just write end.
The file argument must be an object with a write(string)
method; if it is not present or None
, sys.stdout
will be used. Since printed arguments are converted to text strings, print()
cannot be used with binary mode file objects. For these, use file.write(...)
instead.
Whether output is buffered is usually determined by file, but if the flush keyword argument is true, the stream is forcibly flushed.
Changed in version 3.3: Added the flush keyword argument.
————————(我是分割线)————————
中文解释:
print
(*objects, sep=‘ ‘, end=‘\n‘, file=sys.stdout, flush=False)
将对象打印到文本流文件中,用sep分隔,后跟end。sep、end、file和flush(如果存在)必须作为关键字参数给定。
所有非关键字参数都转换为str()那样的字符串,并写入流中,用sep分隔,后跟end。sep和end都必须是字符串;它们也可以是none,这意味着使用默认值。如果没有给定对象,print()将只写结束。
file参数必须是具有write(string)方法的对象;如果不存在或没有,则将使用sys.stdout。由于打印的参数被转换为文本字符串,print()不能用于二进制模式的文件对象。对于这些,请改用file.write(…)。
输出是否缓冲通常由文件决定,但如果flush关键字参数为true,则强制刷新流。
在版本3.3中更改:添加了flush关键字参数。
————————(我是分割线)————————
python print输出延时,让其立刻输出
一句print("ni hao"),很久看不见,怎么让python print能立刻输出呢。
因为python默认是写入stdout缓冲的,使用-u参数启动python,就会立刻输出了。
python3 -u driver.py
————————(我是分割线)————————
参考:
1. Python 3.7.2 documentation
2. RUNOOB.COM:
https://www.runoob.com/python/python-func-print.html
https://www.runoob.com/w3cnote/python3-print-func-b.html
3.
备注:
初次编辑时间:2019年9月22日17:04:59
环境:Windows 7 / Python 3.7.2