In Python \ r role

Python, \ r, role \ r is generally used in the position () to do the processing for formatting the results to be printed, the print represents the cursor back to the start position of the Bank. Here implement a timer function, and no comparison differentiated r \ r of \.


[Python]  plain text view  Copy the code
?
1
2
3
4
5
6
import time
 
# print中没有\r
for i in range ( 1 , 11 ):
     print ( '倒计时:%d' % ( 10 - i), end = '')
     time.sleep( 1 )

 

[Plain Text]  plain text view  Copy the code
?
C:\Python36\python.exe G:/PycharmProjects/帖子/teizi04.py
倒计时:9倒计时:8倒计时:7倒计时:6倒计时:5倒计时:4倒计时:3倒计时:2倒计时:1倒计时:0
Process finished with exit code 0

 

[Python]  plain text view  Copy the code
?
1
2
3
4
5
6
import time
 
# print中有\r
for i in range ( 1 , 11 ):
     print ( '\r倒计时:%d' % ( 10 - i), end = '')
     time.sleep( 1 )

 

[Plain Text]  plain text view  Copy the code
?
C:\Python36\python.exe G:/PycharmProjects/帖子/teizi04.py
倒计时:0
Process finished with exit code 0


These results can be seen, when the print result does not wrap, no \ r The results are appended in the Bank last one, there \ r is the result of the Bank in the beginning of a print coverage of
more technical information may concern: gzitcast

Guess you like

Origin www.cnblogs.com/heimaguangzhou/p/11590743.html