Python 如何延迟一次打印一行多行字符串?

Python 如何延迟一次打印一行多行字符串?,python,python-3.x,Python,Python 3.x,我想输出上面的例子,一次一行,延迟0.5秒。我发现了一种打印字符的方法,这种方法也有同样的效果,但打印字符时会有延迟。分割行;打印时迭代每一行,然后在打印后休眠 string = """This is a very long string, containing commas, that I split up for readability""" import time string = """This is a very long string, containing commas, th

我想输出上面的例子,一次一行,延迟0.5秒。我发现了一种打印字符的方法,这种方法也有同样的效果,但打印字符时会有延迟。

分割行;打印时迭代每一行,然后在打印后休眠

string = """This is a
very long string,
containing commas,
that I split up
for readability"""
import time

string = """This is a
very long string,
containing commas,
that I split up
for readability"""

for line in string.splitlines():
    print(line)
    time.sleep(0.5)