python3 str.encode()_bytes.decode().py
""" python3 str.encode()_bytes.decode().py 参考:https://www.runoob.com/python3/python3-string-encode.html 知识点: 1. str.encode(encoding='UTF-8',errors='strict') -> bytes 对象。 encode() 方法以指定的编码格式编码字符串。errors参数可以指定不同的错误处理方案。 encoding -- 要使用的编码,如: UTF-8。 errors -- 设置不同错误的处理方案。默认为 'strict',意为编码错误引起一个UnicodeError。 其他可能得值有 'ignore', 'replace', 'xmlcharrefreplace', 'backslashreplace' 以及通过 codecs.register_error() 注册的任何值。 该方法返回编码后的字符串,它是一个 bytes 对象。 2. """ str = "菜鸟教程"; str_utf8 = str.encode("UTF-8") str_gbk = str.encode("GBK") print(str) # 菜鸟教程 print("UTF-8 编码:", str_utf8) print("GBK 编码:", str_gbk) # UTF-8