mike
mike

Reputation: 55

why does escape character \b shows an unknown character?

i have a simple line of code

 print("Hello \bWorld!") 

and the output instead of HelloWorld! is

enter image description here

what is the problem ? im using python 3.5. i took the code from w3school.com

Upvotes: 0

Views: 607

Answers (2)

Patrick Artner
Patrick Artner

Reputation: 51683

Your console output is incapeable of displaying the '\b'. This has nothing to do with python.

It works in Visual Studio: You can verify it by setting a breakpoint in your debugger and inspect the value (most IDEs have UTF-8 support) - the windows console f.e. has not.

Debugging output in Visual Studio:

debugger output

vs. console output in windows:

output in console

and (here it looks like yours)

output in output

for

k = "Hello \bWorld!"
print(k)

Upvotes: 1

DirtyBit
DirtyBit

Reputation: 16792

\b

ASCII backspace ( BS ) removes previous character in Python 3.x:

print("ab\bc")

OUTPUT:

ac

In your case its not something related to Python but the console itself.

As I get:

print("Hello \bWorld")   # HelloWorld

pyFiddle

Python Escape Characters

Upvotes: 1

Related Questions