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

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

技术教程推荐

人工智能基础课 -〔王天一〕

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

Electron开发实战 -〔邓耀龙〕

RPC实战与核心原理 -〔何小锋〕

说透元宇宙 -〔方军〕

Vue 3 企业级项目实战课 -〔杨文坚〕

结构思考力 · 透过结构看思考 -〔李忠秋〕

LangChain 实战课 -〔黄佳〕

互联网人的数字化企业生存指南 -〔沈欣〕

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