encoding是编码的意思,在python中,unicode类型是作为编码的基础类型。
python encode() 方法以encoding指定的编码格式编码字符串。errors参数可以指定不同的错误处理方案。
encode()方法语法:(推荐学习:python视频教程)
str.encode(encoding='utf-8',errors='strict')
参数
encoding -- 要使用的编码,如utf-8。
errors -- 设置不同错误的处理方案。默认为 'strict',意为编码错误引起一个unicodeerror。 其他可能得值有 'ignore', 'replace', 'xmlcharrefreplace', 'backslashreplace' 以及通过 codecs.register_error() 注册的任何值。
返回值
该方法返回编码后的字符串。
以下实例展示了encode()方法的实例:
#!/usr/bin/pythonstr = this is string example....wow!!!;print encoded string: + str.encode('base64','strict')
以上实例输出结果如下:
encoded string: dghpcybpcybzdhjpbmcgzxhhbxbszs4uli53b3chise=
更多python相关技术文章,请访问python教程栏目进行学习!
以上就是python中encoding是什么意思的详细内容。
