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('')
浙公网安备 33010602011771号