ciyuanwangcheng

导航

 


1. python3中
  用print('hello'),在这句代码执行完后会将hello缓存到内存中。
  而用print('hello',flust=True),会将缓存中的hello直接显示在屏幕。
2.python3中
  sys.stdout.write('hello')和print('hello')的效果是一样的。
  sys.stdout.flust(),也是将缓存中的hello直接显示在屏幕。
3.python2中
  如果直接使用print('hello',end=True),会报语法错误。
  但是想要和Python3同样的效果就需要在文件的开头加上一句 from __future__ import print_function

看代码:

  1 # -*- coding:utf-8 -*-
  2 #!/usr/bin/python
  3 ######################################################
  4 from __future__ import print_function
  5 import sys
  6 import time
  7 for i in range(30):
  8     print('*', end='')
  9     sys.stdout.flush()
 10     time.sleep(0.2)
 11 print('')

 

 

 引用:https://yunxiaomeng.blog.csdn.net/article/details/104393472?utm_medium=distribute.pc_relevant.none-task-blog-BlogCommendFromMachineLearnPai2-1.channel_param&depth_1-utm_source=distribute.pc_relevant.none-task-blog-BlogCommendFromMachineLearnPai2-1.channel_param

posted on 2020-11-08 22:42  ciyuanwangcheng  阅读(570)  评论(0)    收藏  举报