在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/
在Python中,
是carriagereturn字符,它将光标移动到当前行的开始,允许覆盖原有内容。例如,`print('Pythonisincludedinthistutorial
123456')`会输出`123456isincludedinthistutorial`,因为'
'后的内容覆盖了原本的'Python'。了解这个字符在字符串操作中的作用对于处理文本输出很重要。
957

被折叠的 条评论
为什么被折叠?



