3

How would I print '\x08' as '\x08' in python? If I enter the command

print '\x08'

the output is blank instead of

\x08

3 Answers 3

9

Please use r before string, it means raw string, in which you don't need to escape special chars. For more details about string literal prefixes please read the documentation.

print r'\x08'
Sign up to request clarification or add additional context in comments.

2 Comments

yeah but the string is stored in a variable (i.e. s = '\x08'), how do I print the raw variable?
nvm i found out that i can use .format and format the string variable as a raw string
1

You can just escape '\x08' (backspace character) by doing,

print '\\x08'

Comments

0

In general, you can also do print repr(c).strip("'"), where c is the string you want to view in the code format, ie TAB will show as '\t' and newline as '\n' and so on..

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.