如何將位元組文字轉換成 Python 字串?
要將位元組文字轉換成 Python 字串,您需要對位元組進行解碼。這可以透過對 Bytes 物件執行 decode 方法來完成。
示例
>>> b"abcde".decode("utf-8")
u'abcde'如果 Bytes 表示如下 ASCII 編碼,您還可以將 Bytes 對映到 chr −
bytes = [112, 52, 52]
print("".join(map(chr, bytes)))輸出
p44
廣告
要將位元組文字轉換成 Python 字串,您需要對位元組進行解碼。這可以透過對 Bytes 物件執行 decode 方法來完成。
>>> b"abcde".decode("utf-8")
u'abcde'如果 Bytes 表示如下 ASCII 編碼,您還可以將 Bytes 對映到 chr −
bytes = [112, 52, 52]
print("".join(map(chr, bytes)))p44