a = '\a'
>>> b = '\7'
>>> a == b
True
>>>
How can a
and b
be equal? Can someone give the reason?
\a
is escaped character sequence for control character BEL (a for alert). The character's ASCII code is also happened to be 7, which matches the octal value in the escape sequence \7
.
References:
http://en.wikipedia.org/wiki/Bell_character
http://docs.python.org/reference/lexical_analysis.html#string-literals
They're equal because \a
means the ASCII Bell character in Python. Looking at the ASCII table, the value of that character is 7.
It turns out \a
and \7
have the same value:
>>> a = '\a'
>>> b = '\7'
>>> a
'\x07'
>>> b
'\x07'
\a
is the ASCII Bell (BEL) character (source) which indeed has value 7 in the ASCII table (ASCII table).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With