刚开始学习phthon,发现一个问题,python3里,print都是自动换行的。
现在我想实现这样的一个打印效果:
出现I,停顿2秒,出现am,停顿2秒,出现student!最终出现的一句话是“I am student!”
发现如果是用print(content,end=''),他是把字符都拼接在一起最后一起显示的,不能实现我想要的一个一个出来的效果。
在网上查了很多资料也是无果,请CSDN的大神们,出手吧。
简单的代码如下:
from time import sleep
print("hello,I",end='')
sleep(2)
print("am student!")
在print语句后面加一个逗号,就可以不换行:
from time import sleep
print("hello,I"),
sleep(2)
print("am student!")
以下程序可以实现:
加逗号是Python2.x的用法,而且会在末尾加上空格。在Python3.x中可以这样
print("hello", end="", flush=True)
while True:
pass
print(" world")
flush就是解决由于输出缓冲造成的不实时的问题的