转义序列\ a和\ b之间的区别

时间:2014-01-26 12:45:56

标签: python escaping

我在python idle中尝试了以下语句:

print "This is a \a try"
print "This is a \b try"

两者都给出相同的输出:

enter image description here

我很困惑两者在实际使用中的区别是什么?

2 个答案:

答案 0 :(得分:0)

这些实际上是不同的字符串:

>>> "This is a \a try"
'This is a \x07 try'
>>> "This is a \b try"
'This is a \x08 try'

事实证明,当您打印这些字符串时,符号\x07\x08的显示方式与您的字体相同。

答案 1 :(得分:0)

\a 0x07 Bell or alert
\b 0x08 Backspace

http://www.tutorialspoint.com/python/python_strings.htm