a = 1 print hex(a)
The above gives me the output: 0x1
0x1
How do I get the output as 0x01 instead?
0x01
You can use format :
>>> a = 1 >>> '{0:02x}'.format(a) '01' >>> '0x{0:02x}'.format(a) '0x01'