bab
bab

Reputation: 2169

How to print string version of backspace in python?

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

print '\x08'

the output is blank instead of

\x08

Upvotes: 3

Views: 8204

Answers (3)

Meet Taraviya
Meet Taraviya

Reputation: 889

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..

Upvotes: 0

Marcin Pietraszek
Marcin Pietraszek

Reputation: 3214

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'

Upvotes: 9

Jared
Jared

Reputation: 26397

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

print '\\x08'

Upvotes: 1

Related Questions