Python encode()方法
Python 教程
· 2019-02-02 10:28:36
描述
Python encode() 方法以 encoding 指定的编码格式编码字符串。errors参数可以指定不同的错误处理方案。
语法
encode()方法语法:
str.encode(encoding='UTF-8',errors='strict')
参数
- encoding -- 要使用的编码,如"UTF-8"。
- errors -- 设置不同错误的处理方案。默认为 'strict',意为编码错误引起一个UnicodeError。 其他可能得值有 'ignore', 'replace', 'xmlcharrefreplace', 'backslashreplace' 以及通过 codecs.register_error() 注册的任何值。
返回值
该方法返回编码后的字符串。
实例
以下实例展示了encode()方法的实例:
#!/usr/bin/python
str = "this is string example....wow!!!";
print "Encoded String: " + str.encode('base64','strict')
以上实例输出结果如下:
Encoded String: dGhpcyBpcyBzdHJpbmcgZXhhbXBsZS4uLi53b3chISE=
点击查看所有 Python 教程 文章: https://codercto.com/courses/l/8.html
Basics of Web Design
Terry Felke-Morris / Addison-Wesley / 2013-1-28 / USD 98.40
Basics of Web Design: HTML5 and CSS3, 2e covers the basic concepts that web designers need to develop their skills: * Introductory Internet and Web concepts* Creating web pages with HTML5* Configurin......一起来看看 《Basics of Web Design》 这本书的介绍吧!