Integer to Hexadecimal Conversion in Python

后端 未结 6 1864
执念已碎
执念已碎 2021-01-13 11:37
a = 1
print hex(a)

The above gives me the output: 0x1

How do I get the output as 0x01 instead?

6条回答
  •  醉酒成梦
    2021-01-13 12:20

    print "0x%02x"%a
    

    x as a format means "print as hex".
    02 means "pad with zeroes to two characters".

提交回复
热议问题