Python 中的 decode(encoding='UTF

首页 / Python2入门教程 / Python 中的 decode(encoding='UTF

Python字符串方法decode()使用为编码注册的编解码器解码字符串。它默认为默认的字符串编码。

decode - 语法

Str.decode(encoding='UTF-8',errors='strict')
  • encoding - 编码

  • errors      - 可以设置不同的错误处理方案。错误的默认值是‘Strict',这意味着编码错误会引发UnicodeError。其他可能的值有‘Ignore'、‘replace'、‘xmlcharrefreplace'、‘backslashreplace'和通过codecs.register_error()注册的任何其他名称。

decode - 返回值

解码字符串。

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!!!

祝学习愉快!(内容编辑有误?请选中要编辑内容 -> 右键 -> 修改 -> 提交!)

技术教程推荐

朱赟的技术管理课 -〔朱赟〕

微服务架构实战160讲 -〔杨波〕

快速上手Kotlin开发 -〔张涛〕

iOS开发高手课 -〔戴铭〕

设计模式之美 -〔王争〕

JavaScript核心原理解析 -〔周爱民〕

编程高手必学的内存知识 -〔海纳〕

人人都用得上的数字化思维课 -〔付晓岩〕

Kubernetes入门实战课 -〔罗剑锋〕

好记忆不如烂笔头。留下您的足迹吧 :)