# Python:进制转换 **Published by:** [weigr](https://paragraph.com/@hiweigr/) **Published on:** 2022-03-23 **URL:** https://paragraph.com/@hiweigr/python ## Content # 十进制转二进制 print(bin(12)) # 十进制转十六进制 print(hex(15)) print('%x' % 15) # 小写且不带0x # 十进制转八进制 print(oct(12)) print('%o' % 12) # 任意进制转换为十进制 print(int('ff', 16)) # 16进制255 print(int('14', 8)) # 8进制12 print(int('1010', 2)) # 2进制10 ## Publication Information - [weigr](https://paragraph.com/@hiweigr/): Publication homepage - [All Posts](https://paragraph.com/@hiweigr/): More posts from this publication - [RSS Feed](https://api.paragraph.com/blogs/rss/@hiweigr): Subscribe to updates - [Twitter](https://twitter.com/hiweigr): Follow on Twitter