说明:
>>> help(hex)
Help on built-in function hex in module __builtin__:
hex(...)
hex(number) -> string
Return the hexadecimal representation of an integer or long integer.
>>> help(oct)
Help on built-in function oct in module __builtin__:
oct(...)
oct(number) -> string
Return the octal representation of an integer or long integer.
>>> help(bin)
Help on built-in function bin in module __builtin__:
bin(...)
bin(number) -> string
Return the binary representation of an integer or long integer.
>>>
示例:
print hex(20),hex(-20) #转换成十六进制
print oct(20),oct(-20) #转换成八进制
print bin(20),bin(-20) #转换成二进制
结果:
0x14 -0x14
024 -024
0b10100 -0b10100