encode 和 decode 的使用


txt = '我是字符串' txt_encode = txt.encode() print(txt) # 我是字符串 print(txt_encode) # b'\xe6\x88\x91\xe6\x98\xaf\xe5\xad\x97\xe7\xac\xa6\xe4\xb8\xb2' print(type(txt)) # <class 'str'> print(type(txt_encode)) # <class 'bytes'> txt_copy = txt_encode.decode( ) print(txt_copy) # 我是字符串 print(type(txt_copy)) # <class 'str'> # str->bytes encode # bytes->str decode

2020-05-07


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM