Python3 bytes.decode()方法
发布时间:2019-10-30 点击:46
Python3 bytes.decode()方法
功能:
bytes.decode() 方法以指定的编码格式解码 bytes 对象。默认编码为 'utf-8'。
语法:bytes.decode(encoding="utf-8", errors="strict")
参数:
encoding -- 要使用的编码,默认为"UTF-8"。
errors -- 设置不同错误的处理方案。默认为 'strict',意为编码错误引起一个UnicodeError。 其他可能得值有 'ignore', 'replace', 'xmlcharrefreplace', 'backslashreplace' 以及通过 codecs.register_error() 注册的任何值。
返回值:
返回指定的编码格式解码 bytes 对象
注意事项:
1、与之相对应的是encode编码
实例说明:
>>> str="我爱我家"
>>> str2=str.encode("UTF-8")
>>> str2
b'\xe6\x88\x91\xe7\x88\xb1\xe6\x88\x91\xe5\xae\xb6'
>>> str2.decode("UTF-8")
'我爱我家'
>>>