In Python, how to change text after it's printed?

后端 未结 5 749
名媛妹妹
名媛妹妹 2020-12-17 16:46

I have a Python program I am writing and I want it to be able to change text after it is printed. For example, let\'s say I want to print \"hello\" and erase one letter eve

5条回答
  •  情书的邮戳
    2020-12-17 17:33

    For multi-line output, you can also clear the screen each time and reprint the entire thing:

    from time import sleep
    import os
    
    def cls():
        os.system('cls' if os.name=='nt' else 'clear')
    
    message = 'hello'
    for i in range(len(message), 0, -1):
        cls()
        print message[:i]
        sleep(1)
    

提交回复
热议问题