Q:

storing chr(3) to variable in python output showing junk values

I'm converting some of ascii character to chr, so i used chr() function in python. if execute chr(3) i'll get '\x03' the answer is correct.
when i execute below code i get some junk value
a=chr(3)
print a

output is:
♥

or sometimes output shows junk values.
please tell me how to convert this value to readable format.
please tell me this is very important for me.

A:

You can print it like this, using the repr function:
a=chr(3)
print repr(a)

output:
'\x03'

If you want to get rid of the quotes you could do this:
print repr(a)[1:-1]

output:
\x03

