如何将字节文字转换为 Python 字符串?
pythonserver side programmingprogramming更新于 2025/6/26 10:52:17
要将字节文字转换为 Python 字符串,您需要解码字节。可以使用 bytes 对象上的解码方法完成此操作。
示例
>>> b"abcde".decode("utf-8")
u'abcde'
如果字节表示 ASCII 编码,您还可以将字节映射到 chr,如下所示 −
bytes = [112, 52, 52]
print("".join(map(chr, bytes)))
输出
p44
相关文章
有用资源
python 参考教程 - 该教程包含有关 python 的更多信息:https://www.cainiaomax.com/python/

