Files
Python_CookBook_repo/6.数据编码与处理/10.Base64编码和解码.py
2025-09-10 16:12:45 +08:00

15 lines
386 B
Python
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import base64
if __name__ == '__main__':
# 如果需要使用b64编码对二进制数据做编码和解码操作
s = b'Hello World!'
# 可以使用base64的b64encoder和decoder
a = base64.b64encode(s)
print(a)
b = base64.b64decode(a)
print(b)
# 和上一章一样如果你需要unicode需要再解码一次
a = a.decode('ascii')
print(a)