# Python:binascii库 - 二进制和 ASCII 码互转 **Published by:** [weigr](https://paragraph.com/@hiweigr/) **Published on:** 2022-03-23 **URL:** https://paragraph.com/@hiweigr/python-binascii-ascii ## Content import binascii """ binascii 模块包含很多在二进制和二进制表示的各种ASCII码之间转换的方法 """ s = b'hello' # 返回二进制数据的十六进制表示形式 h = binascii.hexlify(s) print(binascii.hexlify(s)) # OR print(binascii.b2a_hex(s)) # 返回由十六进制字符串表示的二进制数据 print(binascii.a2b_hex(h)) # OR print(binascii.unhexlify(h)) ## 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