Python打印不能立即打印的解决方式

  

<强> 1,问题描述

  

在Python中使用打印打印hello world时,终端不显示

        def hello ():   打印(“hello world !”)      

<强> 2,原因

  

因为标准输入输出stdin和stdout有缓冲区,所以使用打印不能立即打印出来,作为刚接触Python的菜鸟,迷瞪了半天

  

  

1)刷新缓冲区,python中是sys.stdout.flush ()

        导入系统   def hello ():   打印(“hello world !”)   sys.stdout.flush ()      

2) python3中支持印支持参数冲

  

原型:   

  

打印(*对象,9=' '=' \ n '结束,文件系统。stdout,冲洗=False)

           def hello ():   print (“hello world !”冲洗=True)      

参考官方手册

  

https://docs.python.org/zh-cn/3/library/functions.html打印   

以上这篇Python打印不能立即打印的解决方式就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持。

Python打印不能立即打印的解决方式