1. 程式人生 > >python3報錯:TypeError: can't concat bytes to str

python3報錯:TypeError: can't concat bytes to str

erro ring blog error: python3 con decode 解決方法 error

有時會報錯這個:TypeError: Can‘t convert ‘bytes‘ object to str implicitly

解決方法:使用字節碼的decode()方法。

示例:

str = ‘I am string‘
byte = b‘ I am bytes‘
s = str + byte
print(s)

  這時會報錯:TypeError: Can‘t convert ‘bytes‘ object to str implicitly

解決方法:

s = str + byte.decode()

  

python3報錯:TypeError: can't concat bytes to str