分类: Python/Ruby


不明白为什么以下语句:

while True:
for i in ["/","-","|","\\","|"]:
print "%s\b" % i,



while True:
for i in ["/","-","|","\\","|"]:
print "%s\r" % i,

的输出显示跟自己预期相反。

根据下表,
EscapeWhat it does.
\\Backslash ()
\'Single-quote (')
\"Double-quote (")
\aASCII bell (BEL)
\bASCII backspace (BS)
\fASCII formfeed (FF)
\nASCII linefeed (LF)
\N{name}Character named name in the Unicode database (Unicode only)
\r ASCIICarriage Return (CR)
\t ASCIIHorizontal Tab (TAB)
\uxxxxCharacter with 16-bit hex value xxxx (Unicode only)
\UxxxxxxxxCharacter with 32-bit hex value xxxxxxxx (Unicode only)
\vASCII vertical tab (VT)
\oooCharacter with octal value ooo
\xhhCharacter with hex value hh
\r 为回车, \b 为退格,那么我预期输出前者是显示无限排

/ - \ |
/ - \ |
/ - \ |

后者预期输出看起来是 “旋转的杆”。


然而实际结果跟我预测不一样。


这问题先码起来,跳过,以后明白再来思考。