def print(self, *args, sep=' ', end='\n', file=None): # known special case of 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. """ pass
如上所示:
python3 中print函数意义为将value值打印到一个数据流中,默认为系统标准输出(sys.stdout)
print支持一次性打印多个值
sep=' ' :设置打印字符串之间的字符,也就是隔开方式
end='\n':在字符串结尾添加相应的值,默认为换行符
file=sys.stdout:输出流指定
with open('a.txt', 'w') as f: print('OK', file=f)
将‘OK’写入文件