简单介绍Python中的decode()方法的使用
作者:goldensun 时间:2021-01-05 23:47:31
decode()方法使用注册编码的编解码器的字符串进行解码。它默认为默认的字符串编码。
语法
以下是decode()方法的语法:
str.decode(encoding='UTF-8',errors='strict')
参数
encoding -- 这是所使用的编码。对于所有的编码方案的列表,请访问:标准编码库
errors -- 这可能是给定一个不同的错误处理机制。默认的错误是“严格”,即编码错误提出UnicodeError。其他可能的值是ignore', 'replace', 'xmlcharrefreplace', 'backslashreplace' 并通过codecs.register_error().注册的任何其他名称。
返回值
此方法返回的字符串的解码版本。
例子
下面的例子显示了decode()方法的使用。
#!/usr/bin/python
str = "this is string example....wow!!!";
str = str.encode('base64','strict');
print "Encoded String: " + str;
print "Decoded String: " + str.decode('base64','strict')
当我们运行上面的程序,它会产生以下结果:
Encoded String: dGhpcyBpcyBzdHJpbmcgZXhhbXBsZS4uLi53b3chISE=
Decoded String: this is string example....wow!!!
标签:Python
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
Python人脸检测实战之疲劳检测
2021-02-23 16:31:37
![](https://img.aspxhome.com/file/2023/6/76716_0s.jpg)
用Python提取PDF表格的方法
2022-09-23 05:40:38
![](https://img.aspxhome.com/file/2023/5/99465_0s.jpg)
Python Lambda函数使用总结详解
2022-05-07 11:41:31
Js sort排序使用方法
2023-10-19 10:20:55
python/golang实现循环链表的示例代码
2021-10-31 23:32:20
python项目打包成exe和安装包的方法步骤
2023-06-29 08:37:21
![](https://img.aspxhome.com/file/2023/5/112185_0s.jpg)
Python 如何展开嵌套的序列
2022-10-12 03:15:37
asp如何验证IP地址?
2010-06-10 18:37:00
如何远程连接SQL Server数据库
2009-06-08 12:41:00
![](https://img.aspxhome.com/file/UploadPic/20096/8/mssql01-56s.jpg)
关于python爬虫应用urllib库作用分析
2023-11-02 12:59:43
![](https://img.aspxhome.com/file/2023/9/63249_0s.png)
Python如何合并多个字典或映射
2023-11-07 17:20:51
Python用zip函数同时遍历多个迭代器示例详解
2023-09-28 06:09:41
使用python快速在局域网内搭建http传输文件服务的方法
2021-02-12 10:44:19
![](https://img.aspxhome.com/file/2023/9/95759_0s.png)
一篇文章搞懂python混乱的切换操作与优雅的推导式
2023-09-15 00:25:10
![](https://img.aspxhome.com/file/2023/9/99549_0s.png)
css样式表使用技巧小结
2008-01-11 20:44:00
Django应用程序入口WSGIHandler源码解析
2021-07-09 04:33:22
ASP文件中的安全问题
2011-04-14 11:15:00
Python装饰器的函数式编程详解
2023-12-27 16:35:31
Javascript DOM 编程实例讲解--仿LightBox效果提示框
2008-05-01 13:25:00
![](https://img.aspxhome.com/file/UploadPic/up/2008050116095611.gif)
Android界面与交互设计原则
2012-02-04 09:28:32