在Python string中,\t
和\n
都是比较常见的,分别代表tab和new line,而\r比较不常见,这里简单介绍以下\r
的用法。
\r
的英文是carriage return,即将\r
出现位置的cursor转移到这行的开头,\r
后面的文字就会覆盖这行开头的文字,直到这行结束。
一个例子:
print('Python is included in this tutorial\r123456')
>>> '123456 is included in this tutorial'
即\r
出现,cursor跳到该行开头,继续输入'123456'
,并覆盖掉了原有的'Python'
参考:
https://www.codespeedy.com/how-does-carriage-return-work-in-python/