小白教程
所有教程
关于
Search
172.69.58.215
172.69.58.215
参数设置
贡献
退出
操作
编辑
移动
保护
信息
历史
删除
查看“Python3 string decode”的源代码
本页内容
上一节:
Python3_string_count
下一节:
Python3_string_encode
因为以下原因,您没有权限编辑本页:
您请求的操作仅限属于该用户组的用户执行:
用户
您可以查看和复制此页面的源代码。
{{DISPLAYTITLE:bytes.decode(encoding="utf-8", errors="strict")}}[[Category:python3 string|4]] = Python3 bytes.decode()方法 = [[python3 string|Python3 字符串]] == 描述 == decode() 方法以指定的编码格式解码 bytes 对象。默认编码为 'utf-8'。 == 语法 == decode()方法语法: <sample title="" desc="" lang="python" hererun="1"> bytes.decode(encoding="utf-8", errors="strict") </sample> == 参数 == * encoding -- 要使用的编码,如"UTF-8"。 * errors -- 设置不同错误的处理方案。默认为 'strict',意为编码错误引起一个UnicodeError。 其他可能得值有 'ignore', 'replace', 'xmlcharrefreplace', 'backslashreplace' 以及通过 codecs.register_error() 注册的任何值。 == 返回值 == 该方法返回解码后的字符串。 以下实例展示了decode()方法的实例: == 实例(Python 3.0+) == <sample title="" desc="" lang="python" hererun="1"> #!/usr/bin/python3 str = "小白教程"; str_utf8 = str.encode("UTF-8") str_gbk = str.encode("GBK") print(str) print("UTF-8 编码:", str_utf8) print("GBK 编码:", str_gbk) print("UTF-8 解码:", str_utf8.decode('UTF-8','strict')) print("GBK 解码:", str_gbk.decode('GBK','strict')) </sample> 以上实例输出结果如下: <sample title="" desc="" lang="python" hererun="1"> 小白教程 UTF-8 编码: b'\xe8\x8f\x9c\xe9\xb8\x9f\xe6\x95\x99\xe7\xa8\x8b' GBK 编码: b'\xb2\xcb\xc4\xf1\xbd\xcc\xb3\xcc' UTF-8 解码: 小白教程 GBK 解码: 小白教程 </sample> [[python3 string|Python3 字符串]]
返回至“
Python3 string decode
”。
上一节:
Python3_string_count
下一节:
Python3_string_encode