Python integer to hex string
<p>Consider an integer 2. I want to convert it into hex string '0x02'. By using python's build-in function hex, I can get '0x2' which is not suitable for my code. Can any one show me how to get what I want in a convenient way. Thank you. </p>

<pre><code>integer = 2
hex_string = '0x{:02x}'.format(integer)
</code></pre>

<p>See <a href="https://www.python.org/dev/peps/pep-3101/" rel="nofollow">pep 3101</a>, especially <em>Standard Format Specifiers</em> for more info.</p>

python hex