Print in one line dynamically

后端 未结 20 3654
梦谈多话
梦谈多话 2020-11-21 23:32

I would like to make several statements that give standard output without seeing newlines in between statements.

Specifically, suppose I have:

for it         


        
20条回答
  •  暖寄归人
    2020-11-22 00:00

    The best way to accomplish this is to use the \r character

    Just try the below code:

    import time
    for n in range(500):
      print(n, end='\r')
      time.sleep(0.01)
    print()  # start new line so most recently printed number stays
    

提交回复
热议问题