Python3 print简介

def print(self, *args, sep=' ', end='
', file=None): # known special case of print
    """
    print(value, ..., sep=' ', end='
', 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=' ':在字符串结尾添加相应的值,默认为换行符

file=sys.stdout:输出流指定

with open('a.txt', 'w') as f:
    print('OK', file=f)

 将‘OK’写入文件

flush=False:是否清空流

以前-好记性不如烂笔头 现在-好记性不如烂键盘
原文地址:https://www.cnblogs.com/gexbooks/p/14835401.html