- 其他进制转十进制
Python终端进入之后,直接输入要转换的对象回车即可,或者用*int()*函数来实现
appledeMacBook-Pro:girl apple$ python
Python 3.6.0 |Anaconda 4.3.1 (x86_64)| (default, Dec 23 2016, 13:19:00)
[GCC 4.2.1 Compatible Apple LLVM 6.0 (clang-600.0.57)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> 0b10
2
>>> 0o10
8
>>> 0x10
16
>>> int(0x10)
16
- 其他进制转二进制 可以用*bin()*函数来做转换
>>> bin(10)
'0b1010'
>>> bin(0o7)
'0b111'
>>> bin(0xE)
'0b1110'
- 其他进制转八进制 *oct()*函数
>>> oct(0b111)
'0o7'
>>> oct(0x111)
'0o421'
- 其他进制转十六进制 *hex()*函数
>>> hex(888)
'0x378'
>>> hex(0o777)
'0x1ff'