python hex() oct() bin() 内置函数

来源:互联网 发布:linux gpu使用率 编辑:程序博客网 时间:2024/05/16 01:16

说明:

>>> 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



1 0