title: Print a variable in hexadecimal in Python
body: <p>I'm trying to find a way to print a string in hexadecimal. For example, I have this string which I then convert to its hexadecimal value.</p>
  
  <pre><code>my_string = "deadbeef"
  my_hex = my_string.decode('hex')
  </code></pre>
  
  <p>How can I print <code>my_hex</code> as <code>0xde 0xad 0xbe 0xef</code>?</p>
  
  <p>To make my question clear... Let's say I have some data like <code>0x01, 0x02, 0x03, 0x04</code> stored in a variable. Now I need to print it in hexadecimal so that I can read it. I guess I am looking for a Python equivalent of <code>printf("%02x", my_hex)</code>. I know there is <code>print '{0:x}'.format()</code>, but that won't work with <code>my_hex</code> and it also won't pad with zeroes.</p>