Python字符串方法decode()使用为编码注册的编解码器解码字符串。它默认为默认的字符串编码。
Str.decode(encoding='UTF-8',errors='strict')
encoding - 编码
errors - 可以设置不同的错误处理方案。错误的默认值是‘Strict',这意味着编码错误会引发UnicodeError。其他可能的值有‘Ignore'、‘replace'、‘xmlcharrefreplace'、‘backslashreplace'和通过codecs.register_error()注册的任何其他名称。
解码字符串。
#!/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!!!
祝学习愉快!(内容编辑有误?请选中要编辑内容 -> 右键 -> 修改 -> 提交!)