PyCharm print end='\r' statement not working

后端 未结 2 1908
旧巷少年郎
旧巷少年郎 2021-02-13 05:24

There are already lots of other questions about the print statement, but I have not found an answer to my problem:

When I do:

for idx in range(10):
    p         


        
2条回答
  •  暗喜
    暗喜 (楼主)
    2021-02-13 06:07

    Try:

        for idx in range(10):
            print('\r', idx, end='')
    

    Carriage return at front, and end with '' to avoid new line '\n'. One solution to avoid the space is to use the format convention:

        for idx in range(10):
            print("'\r{0}".format(idx), end='')
    

提交回复
热议问题