Printing a string with a little delay between the chars

前端 未结 7 1588
青春惊慌失措
青春惊慌失措 2020-12-19 23:20

I want a text to be displayed as if it is just being typed. So I need a little delay after every letter.

I tried to do it this way:

import time

text         


        
7条回答
  •  孤城傲影
    2020-12-19 23:50

    Your example prints them all on separate lines I think (at least on windows). You can use printing to sys.stdout to get around this.

    import time, sys
    for character in text:
        sys.stdout.write(character)
        time.sleep(0.2)
    

提交回复
热议问题