a = 1
print hex(a)
The above gives me the output: 0x1
How do I get the output as 0x01
instead?
You can use format
:
>>> a = 1
>>> '{0:02x}'.format(a)
'01'
>>> '0x{0:02x}'.format(a)
'0x01'
>>> format(1, '#04x')
'0x01'
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With