You want to encode the string with the string_escape codec:
print s.encode('string_escape')
or you can use the repr() function, which will turn a string into it's python literal representation including the quotes:
print repr(s)
Demonstration:
>>> s = "String:\tA" >>> print s.encode('string_escape') String:\tA >>> print repr(s) 'String:\tA'
In Python 3, you'd be looking for the unicode_escape codec instead:
print(s.encode('unicode_escape'))
which will print a bytes value. To turn that back into a unicode value, just decode from ASCII:
>>> s = "String:\tA" >>> print(s.encode('unicode_escape')) b'String:\\tA' >>> print(s.encode('unicode_escape').decode('ASCII')) String:\tA