Python3 string.decode()方法

decode() 方法使用编码注册的编解码器解码该字符串。它默认是使用系统默认的字符串编码。

语法

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

参数

  • encoding -- 这是要使用的编码。对于所有的编码方案的列表,请访问:标准编码

  • errors -- 这可以给出用来设置一个不同的错误处理方案。这里默认的错误是“strict”,即编码错误引发一个UnicodeError。

    其他可能的值是 'ignore', 'replace', 'xmlcharrefreplace', 'backslashreplace' 并通过 codecs.register_error() 注册的其他名称。

返回值

字符串解码

示例

#!/usr/bin/python3

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

上一篇: Python3数字 下一篇: Python3字符串