官方文档

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.

参数解析
value:需要输出的值,可以是多个,用”,”分隔。
sep:多个输出值之间的间隔,默认为一个空格。
end:输出语句结束以后附加的字符串,默认是换行(’\n’)。
file:输出的目标对象,可以是文件也可以是数据流,默认是“sys.stdout”。
flush:flush值为True或者False,默认为Flase,表示是否立刻将输出语句输出到目标对象。

演示

默认:print(value, …, sep=’ ‘, end=’\n’, file=sys.stdout, flush=False)

>>> print("hello world")
hello world

1
    2

当value有多个:

>>> print("hello","world")
hello world

1
    2

当sep为”,”

>>> print("hello","world",sep=",")
hello,world

1
    2

当end为“”

>>>print("hello","world",end="")
>>>print("hello","world")
hello worldhello world

1
    2
    3

当file指向test.txt

test = open("test.txt", "w")
print("hello","world",sep="\n", file=test)

1
    2
    3

此时当前目录下会新建一个test.txt文件里面内容为

hello
world

1
    2

flush=False
该参数只有两个选项True or False。
当flush=False时,输出值会存在缓存,然后在文件被关闭时写入。
当flush=True时,输出值强制写入文件。
原文:https://blog.csdn.net/weixin_41939225/article/details/79782793

最新文章

  1. linux mount/umount挂载命令解析。
  2. 了解 Office 365
  3. Linux 网络编程七(非阻塞socket:epoll--select)
  4. C#实现对指定文件夹中文件按修改时间排序
  5. 《响应式Web设计—HTML5和CSS3实战》 学习记录
  6. 用Stax方式处理xml
  7. 1.各个浏览器内核?经常遇到的浏览器兼容性有哪些?解决办法?常用的hack技巧?
  8. DFS(dfs)
  9. spring2.0 mybatis JDBC配置
  10. 关于PHP5.6连接SqlServer
  11. python-*args和**kwargs作用和区别
  12. Web界面进行用户管理
  13. SqlDataAdapter介绍【五】
  14. 数据迁移_老集群RAC迁移数据恢复到新集群RAC
  15. 剑指offer二之替换空格
  16. Xamarin-Android_BaseAdapter 简单的复用
  17. Android: INSTALL_FAILED_UPDATE_INCOMPATIBLE错误解决措施
  18. 部分Android或IOS手机拍照后照片被旋转的问题
  19. quality center 支持的平台
  20. Delphi Dll 动态调用例子(2)

热门文章

  1. NBUT 1223 Friends number 2010辽宁省赛
  2. cmd 环境变量设置的简单方法
  3. windows运行打开服务命令
  4. Struck: Structured Output Tracking with Kernels
  5. SIM800C 透传模式
  6. CodeForces - 285E: Positions in Permutations(DP+组合数+容斥)
  7. (转)Linux 定时关机、休眠命令
  8. LG3812 【模板】线性基
  9. 在虚拟机中使用Ghost系统盘安装
  10. zz 牛人啊