a = 1 print hex(a)
上面给了我输出: 0x1
0x1
我如何获得输出0x01呢?
0x01
您可以使用format:
format
>>> a = 1 >>> '{0:02x}'.format(a) '01' >>> '0x{0:02x}'.format(a) '0x01'