What does back-slash b do in Python?

What is the purpose of the backslash b in python, I executed print "\" foo \ bar " in the python interpreter and got this result:

>>>print "\"foo\bar" "foar 
+8
python string
source share
2 answers

See string literals documentation:

\b ASCII Backspace (BS)

It creates a backspace character. When you type this character, your terminal has stepped over the second o .

+10
source share

\b is a space character

 \b ASCII Backspace (BS) 

If you want to print the string \foo\bar , do the following:

 >>> print r"\foo\bar" \foo\bar 

This uses the raw strings available in python.

String literals may optionally have a prefix with the letter "r" or "R"; these lines are called raw lines and use different rules to interpret backslash escape sequences

+3
source share

All Articles