Q:

Print confusion

I am new to python when i try to print "\20%" that is
>>>"\20%"

why is the shell printing '\x10%' that is, it is showing
'\x10%'

the same is happening with join also when is do
>>>l = ['test','case']
>>>"\20%".join(l)

it shows
'test\x10%case'

I am using python 2.7.3

A:

'\20' is an octal literal, and the same as chr(2 * 8 + 0) == chr(16).
What the Python shell displays by default is not the output of print, but the representation of the given value, which is the hexadecimal '\x10'.
If you want the string \20%, you have to either escape the backaslash ('\\20%') or use a raw string literal (r'\20%'). Both will be displayed as
>>> r'\20%'
'\\20%'

