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>

<p>Simply add a leading zero if needed:</p>

<pre><code>'0x' + hex(i)[2:].rjust(2, '0')
</code></pre>

python hex