str->bytes:encode編碼
bytes->str:decode解碼
字符串通過編碼成爲字節碼,字節碼通過解碼成爲字符串
其中decode()與encode()方法可以接受參數,其聲明分別爲:
bytes.decode(encoding="utf-8", errors="strict")
str.encode(encoding="utf-8", errors="strict")
其中的encoding是指在解碼編碼過程中使用的編碼方案,errors是指錯誤的處理方案。
特別注意 讀取文件時如果參數是‘rb’,則讀出來已經是bytes類型