天天看点

python decode方法_Python中decode()方法有哪些功能?

摘要:

下文讲述Python中decode()的方法的功能简介说明,如下所示:

decode()方法功能:

使用指定编码格式对bytes对象进行解码,

缺省编码格式为“utf-8”

decode()方法语法

bytesObj.decode([encoding='utf-8'][,errors='strict'])

--------参数说明--------

bytesObj:待解码的bytes对象

encoding:可选参数

待使用的编码

默认编码为 'utf-8'

errors:可选参数,

设置不同错误的处理方案

缺省值为 'strict'

为一个UnicodeError

其它值有 'ignore', 'replace', 'xmlcharrefreplace', 'backslashreplace'

及通过 codecs.register_error() 注册的其它值

--------返回值说明--------

返回一个解码后的字符串

例:

字符串之decode()方法的示例分享

#maomao365.com

#decode()函数的示例分享

S = "猫猫教程";

S_utf8 = S.encode("UTF-8");

print(S_utf8)

S_ = S_utf8.decode('UTF-8');

print(S_);

//输出

b'\xe7\x8c\xab\xe7\x8c\xab\xe6\x95\x99\xe7\xa8\x8b'

猫猫教程