Python3.5里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 and file, 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。sep的默认值是空,end默认值是换行,file的默认值是标准输出流,flush的默认值是非。如果想要自定义sep、end和file,就必须对这几个关键词进行赋值。
  • 该函数将会像str()函数一样,把所有非关键字声明转化为字符串,然后写入输出流。sep和end的赋值必须是字符串,而且可以省略,即使用默认值。如果没有把类赋予print(),那么它就输出换行符号。
  • file声明必须是一个用写入字符串方法打开的类。如果它被省略,或被赋值为None,编译器默认使用sys.stdout,即标准输出。由于被打印的声明被转化为字符串,所有print()无法对二进制模式的文件进行写入。如果要写入二进制模式的文件,使用file.write()。(这里也可以使用sys.stderr,即标准错误。sys.stderr在默认情况下也是输出到显示屏上。)
  • 输出是否缓冲常常由文件决定,但是如果flush关键字的声明为真,输出流将会被强制刷新(里面的数据全部丢失)。
  • 3.3版本的额改动:加入了flush关键词声明。

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值