Search code examples
pythonpython-3.6backspaceescaping

puzzled about what's going on behind \b ( backspacing ) in python3


I was learning the basics about the escape string \ and stumbled into \b I was testing things using \b and figured that it involves cursor moving backward for one spot, and whatever that comes after \b could overwrite. However, with such limited knowledge, I failed to understand why the above script does not print anything out in the Command Line Interface. What's going on in behind the code.

print("a\b", end='')
print("a\b", end='')
print("a\b", end='')
print("a\b", end='')

The code prints out nothing. I thank you in advance for any precious advice


Solution

  • From here, read:

    he backspace doesn't delete anything, it moves the cursor to the left and it gets covered up by what you write afterwards.

    Here you are printing one character, moving the cursor to the left, then printing the empty string "" on top of it. To get a clearer idea, try:

    >>> print("hh\b", end="")
    

    The output looks like:

    h>>>