encode()方法返回字符串的编码版本。默认编码是当前的默认字符串编码。错误可以给定设置一个不同的错误处理方案。
语法
str.encode(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!!!"; print "Encoded String: " + str.encode('base64','strict')
结束
Encoded String: dGhpcyBpcyBzdHJpbmcgZXhhbXBsZS4uLi53b3chISE=
上一篇:
Python3数字
下一篇:
Python3字符串