首页 > 编程语言 > 详细

Python3 print简介

时间:2021-06-03 10:35:17      阅读:28      评论:0      收藏:0      [点我收藏+]
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’写入文件

flush=False:是否清空流

Python3 print简介

原文:https://www.cnblogs.com/gexbooks/p/14835401.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!