功能:
encode() 方法可以使用指定的编码格式来编码字符串。
语法:str.encode(encoding='UTF-8',errors='strict')参数说明:
encoding -- 需要使用的编码,如: UTF-8。
errors -- 设置不同错误的处理方案。默认为 'strict',意为编码错误引起一个UnicodeError。 其他可能得值有 'ignore', 'replace', 'xmlcharrefreplace', 'backslashreplace' 以及通过 codecs.register_error() 注册的任何值。
返回值:该方法将会返回编码后的字符串,它是一个 bytes 对象。与之对应的是解码decode().
注意事项:1、编码的是字符串,但是编码后的是bytes对象,注意类型
2、字符串其余方法见:http://www.mihuguan.com/article/15703730746.html
实例说明:
>>> str="我爱我家" >>> str2=str.encode("UTF-8") >>> str2 b'\xe6\x88\x91\xe7\x88\xb1\xe6\x88\x91\xe5\xae\xb6' >>> str2.decode("UTF-8") '我爱我家' >>>
jQuery2021-01-08
jQuery2021-01-07
MySQL2020-12-13
电脑2020-12-12
服务器2020-12-06
电脑2020-10-06