decode()方法使用注冊(cè)編碼的編解碼器的字符串進(jìn)行解碼。它默認(rèn)為默認(rèn)的字符串編碼。
語法
以下是decode()方法的語法:
str.decode(encoding='UTF-8',errors='strict')
參數(shù)
返回值
此方法返回的字符串的解碼版本。
例子
下面的例子顯示了decode()方法的使用。
#!/usr/bin/pythonstr = "this is string example....wow!!!";str = str.encode('base64','strict');print "Encoded String: " + str;print "Decoded String: " + str.decode('base64','strict')當(dāng)我們運(yùn)行上面的程序,它會(huì)產(chǎn)生以下結(jié)果:
Encoded String: dGhpcyBpcyBzdHJpbmcgZXhhbXBsZS4uLi53b3chISE=Decoded String: this is string example....wow!!!
新聞熱點(diǎn)
疑難解答
圖片精選