如果我们在 Python [Pycharm] 中使用 \r,预期的输出是什么?

What is the expected output if we use \r in Python [Pycharm]?

我在 Pycharm 中写了 print("Hell\rLol"),我得到的输出是 Lol 而不是 Loll.And 在线 IDE 给出了输出 Hell 哈哈

对于其他人所说的 \r 的工作方式以及它在 Pycharm 上的实际工作方式,存在太多混淆。 [OS : Windows 10]

您在字符串中使用了所谓的 Carriage Return \r,因此此符号 之后的子字符串“Lol”\r 将移动到下一行。

执行程序后:

print("Hell\rLol")

您控制台上的结果将是:

Hell
Lol

如果您有兴趣了解有关转义字符的更多信息,请查看此 https://www.w3schools.com/python/gloss_python_escape_characters.asp