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