a = 1 print hex(a)
The above gives me the output: 0x1
0x1
How do I get the output as 0x01 instead?
0x01
Here is f-string variant for Python 3.6+:
a = 1 print(f"{a:0>2x}")
Explanation of string formatting:
:
0
>
2
x
hex
Source: 6.1.3.1 Format Specification Mini-Language