python的print函数中file_【Python-1】初解print函数

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.

print函数可将对象以字符串的形式输出到流文件对象file中,输出对象以sep隔开,以end结尾。sep、end、flie和flush如果需要指定(不使用默认参数),则都必须被当做关键字参数,(关键字参数的意思,就是用等式的显性形式给关键字参数赋值,不能用逗号隔开,按照顺序赋值)

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.

所有的非关键字参数(即待输出对象)将被转化成字符串对象输出到流文件中,以sep隔开,以end结尾。sep和end参数都必须是字符串格式,如果为空,则使用默认值。当print函数无任何参数时,则输出为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.

文件参数必须是一个具有字符串写入方法的对象,如果为空或者不存在,则使用标准的系统输出sys.stdout。因为所有的输出参数都被转化为字符串文本,print()不能是二进制形式的文件对象,所以,使用文件的write方法代替

Whether output is buffered is usually determined by file, but if the flush keyword argument is true, the stream is forcibly flushed.

flush是立即将非关键字内容输出到流文件,不作缓存,正常情况下print到文件中的内容先存到内存中,当文件对象关闭时才把内容输出到文件中,当flush=True时它会立即把内容刷新存到文件中

你可能感兴趣的:(python的print函数中file_【Python-1】初解print函数)