教程集 www.jiaochengji.com
教程集 >  Python编程  >  Python入门  >  正文 Python decode()方法

Python decode()方法

发布时间:2021-12-11   编辑:jiaochengji.com
教程集为您提供Python decode()方法等资源,欢迎您收藏本站,我们将为您提供最新的Python decode()方法资源

描述

Python decode() 方法以 encoding 指定的编码格式解码字符串。默认编码为字符串编码。

语法

decode()方法语法:

<pre class="brush:html;toolbar:false">string.decode(encoding='UTF-8',errors='strict')</pre>

参数

encoding -- 要使用的编码,如"UTF-8"。

errors -- 设置不同错误的处理方案。默认为 'strict',意为编码错误引起一个UnicodeError。 其他可能得值有 'ignore', 'replace', 'xmlcharrefreplace', 'backslashreplace' 以及通过 codecs.register_error() 注册的任何值。

返回值

该方法返回解码后的字符串。

实例

以下实例展示了decode()方法的实例:

<pre class="brush:html;toolbar:false">#!/usr/bin/python   string = "this is string example....wow!!!" string = string.encode('base64','strict')   print "Encoded String: "   string print "Decoded String: "   string.decode('base64','strict')</pre>

以上实例输出结果如下:

<pre class="brush:html;toolbar:false">Encoded String: dGhpcyBpcyBzdHJpbmcgZXhhbXBsZS4uLi53b3chISE=   Decoded String: this is string example....wow!!!</pre>

<span style="color: rgb(0, 0, 0); font-family: Verdana, sans-serif; font-size: 15px; white-space: normal; background-color: rgb(255, 255, 255);">
</span>

您可能感兴趣的文章:
Python decode()方法
什么是Python的字符串
PHP DES加解密方法代码
Python中的gbk怎么转化成utf
python command乱码怎么解决
python怎么调用js中的函数
执行python脚本出现乱码怎么解决
python 怎么调用js
python json中文乱码怎么解决
python中cookie中文乱码怎么解决

上一篇:Python find()方法 下一篇:Python encode()方法
[关闭]
~ ~