Use
print " ".join("0x%s"%my_string[i:i+2] for i in range(0, len(my_string), 2))
like this:
>>> my_string = "deadbeef"
>>> print " ".join("0x%s"%my_string[i:i+2] for i in range(0, len(my_string), 2))
0xde 0xad 0xbe 0xef
>>>
On an unrelated side note ... using string
as a variable name even as an example variable name is very bad practice.