共計 220 個字符,預計需要花費 1 分鐘才能閱讀完成。
可以使用 bytes 對象的 decode()方法將其轉(zhuǎn)換為字符串。
示例代碼如下:
# 定義一個 bytes 對象
b = b'hello world'
# 將 bytes 轉(zhuǎn)換為字符串
s = b.decode()
# 打印結果
print(s) # 輸出:hello world
另外,decode()方法還可以接受一個參數(shù)來指定編碼方式,默認為 utf-8。例如,如果 bytes 對象使用的是 gbk 編碼,可以使用 b.decode('gbk')
來進行轉(zhuǎn)換。
丸趣 TV 網(wǎng) – 提供最優(yōu)質(zhì)的資源集合!
正文完