Thes\x
escape denotes a character encoded by the single-byte hex value given by the next two characters. For example, the capital letter 'N
' has the value 78, which is 4e
in hex. Hence,
>>> '\x4e'
'N'
The backspace "character'' is encoded as hex 08
, which is why \b
is equivalent to \x08
:
>>> 'hello\b\b\b\b\bgoodbye'
'hello\x08\x08\x08\x08\x08goodbye'
Sending this string to the print()
function outputs the string formed by the sequence of characters in this string literal:
>>> print('hello\b\b\b\b\bgoodbye')
goodbye