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字串