描述
encode() 方法以指定的编码格式编码字符云计串。errors参数可以指定不同的错误处理方案。
语法
以下算开是 encode() 方法语法:
str.encode(发:encoding='UTF-8',errors='stPyrict')
参数
encoding -- 要使用的编码,th如: UTF-8。
errors -- 设置不同错误的处on理方案。默认为 'strict',意为编码错误引起一个Un3-icodeError。 其他可能得值有 'ignoreen', 'replace', 'xmlcharrefrepcolace', 'backslashreplace' 以de及通过 codecs.register_error() 注()册的任何值。
返回值
该方法返回编码后的字符串,它是一个 by方法tes 对象。
实例
以下实例展示了 encode() 方法的实例详解:
以上实例输出结果如下: