Why the result of print('helloo\b')
is not hello
and also result of print('heeee\b\b\blo')
is not hello
?
The answers are helloo
and heloe
.
Why the result of print('helloo\b')
is not hello
and also result of print('heeee\b\b\blo')
is not hello
?
The answers are helloo
and heloe
.
Why the result of print('helloo\b') is not 'hello'
Because \b
does not remove characters, it just moves the cursor back one position. Since there is nothing after the \b
, nothing was overwritten. You end up with something like:
hello
^
Where ^
is the cursor.
and also result of print('heeee\b\b\blo') is not 'hello? the answers are 'helloo' and 'heloe'
Because in this you did move the cursor back 3 positions and wrote lo
over the second and third e
s:
heeee
^
Becomes:
heloe
Note that all this is about printing the string somewhere like a terminal that recognizes the backspace character (given what you mention that you "see" in the question) -- the string in memory is still the same, including the \b
characters. See e.g. The "backspace" escape character '\b': unexpected behavior? as well.