Python 基礎(chǔ)教程
Python encode() 方法以 encoding 指定的編碼格式編碼字符串。errors參數(shù)可以指定不同的錯誤處理方案。
encode()方法語法:
str.encode(encoding='UTF-8',errors='strict')
該方法返回編碼后的字符串。
以下實例展示了encode()方法的實例:
#!/usr/bin/python str = "this is string example....wow!!!"; print "Encoded String: " + str.encode('base64','strict')
以上實例輸出結(jié)果如下:
Encoded String: dGhpcyBpcyBzdHJpbmcgZXhhbXBsZS4uLi53b3chISE=