69pao国产精品视频-久久精品一区二区二三区-精品国产精品亚洲一本大道-99国产综合一区久久

Python encode()方法

Python encode()方法

Python 字符串Python 字符串

Python encode() 方法以 encoding 指定的編碼格式編碼字符串。errors參數(shù)可以指定不同的錯(cuò)誤處理方案。

 

語(yǔ)法

encode()方法語(yǔ)法:

str.encode(encoding='UTF-8',errors='strict')

 

參數(shù)

  • encoding -- 要使用的編碼,如"UTF-8"。
  • errors -- 設(shè)置不同錯(cuò)誤的處理方案。默認(rèn)為 'strict',意為編碼錯(cuò)誤引起一個(gè)UnicodeError。 其他可能得值有 'ignore', 'replace', 'xmlcharrefreplace', 'backslashreplace' 以及通過(guò) codecs.register_error() 注冊(cè)的任何值。

 

返回值

該方法返回編碼后的字符串。

 

實(shí)例

以下實(shí)例展示了encode()方法的實(shí)例:

#!/usr/bin/python

str = "this is string example....wow/b64/";
print "Encoded String: " + str.encode('base64','strict')

以上實(shí)例輸出結(jié)果如下:

Encoded String: dGhpcyBpcyBzdHJpbmcgZXhhbXBsZS4uLi53b3chISE=

Python 字符串Python 字符串

下一節(jié):Python expandtabs()方法

Python 教程

相關(guān)文章