python

python3中base64编码解码怎么实现

小亿
391
2024-04-03 15:35:56
栏目: 编程语言
Python开发者服务器,限时0元免费领! 查看>>

在Python3中,可以使用内置的base64模块来进行base64编码和解码操作。下面是一个简单的示例:

import base64

# 要编码的字符串
original_string = "Hello, world!"

# 进行base64编码
encoded_string = base64.b64encode(original_string.encode()).decode()
print("Encoded string:", encoded_string)

# 进行base64解码
decoded_string = base64.b64decode(encoded_string).decode()
print("Decoded string:", decoded_string)

在上面的示例中,首先将原始字符串编码为字节流,然后使用base64.b64encode方法进行编码。然后再使用base64.b64decode方法进行解码,并最后将解码后的字节流转换为字符串。

亿速云「云服务器」,即开即用、新一代英特尔至强铂金CPU、三副本存储NVMe SSD云盘,价格低至29元/月。点击查看>>

相关推荐:php中base64编码和解码怎么实现

0
看了该问题的人还看了