Python中encode()方法的使用简介
作者:goldensun 时间:2023-09-22 15:26:38
encode() 方法返回字符串的编码版本。默认编码是当前的默认字符串编码。可给予设置不同的错误处理机制。
语法
以下是encode()方法的语法:
str.encode(encoding='UTF-8',errors='strict')
参数
encoding -- 这是所使用的编码。对于所有的编码方案的列表,请访问:标准编码库
errors -- 这可能是给定一个不同的错误处理机制。默认的错误是“严格”,即编码错误提出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
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
使用MySQL内建复制功能
2009-12-15 21:36:00
node.js+express+mySQL+ejs+bootstrop实现网站登录注册功能
2023-07-15 17:55:01
![](https://img.aspxhome.com/file/2023/9/55989_0s.gif)
用header 发送cookie的php代码
2023-07-11 11:15:06
Python torch.fft.rfft()函数用法示例代码
2022-02-15 02:03:36
怎样使MySQL在攻击者面前保持安全
2008-11-17 20:09:00
pytorch中index_select()的用法详解
2022-01-20 19:44:05
JS:firefox 兼容性问题
2009-08-01 16:20:00
perl哈希hash的常见用法介绍
2023-08-12 18:46:59
Django+Nginx+uWSGI 定时任务的实现方法
2022-11-14 16:02:57
Vue3.0 自己实现放大镜效果案例讲解
2024-04-09 10:45:54
![](https://img.aspxhome.com/file/2023/2/139852_0s.png)
PHP 数组和字符串互相转换实现方法
2023-06-19 15:04:17
Pycharm无法打开双击没反应的问题及解决方案
2021-09-06 07:34:30
![](https://img.aspxhome.com/file/2023/4/90574_0s.png)
python3安装OCR识别库tesserocr过程图解
2021-12-08 04:50:08
![](https://img.aspxhome.com/file/2023/9/128519_0s.png)
python logging模块的使用总结
2021-11-15 06:46:53
Python离线安装PIL 模块的方法
2023-02-19 22:38:37
![](https://img.aspxhome.com/file/2023/0/135010_0s.jpg)
一文教会你如何运行vue项目
2024-05-28 15:54:33
![](https://img.aspxhome.com/file/2023/5/123125_0s.jpg)
MySQL多表查询的具体实例
2024-01-22 00:13:20
Django框架基础模板标签与filter使用方法详解
2022-10-25 18:14:43
![](https://img.aspxhome.com/file/2023/5/66295_0s.png)
详细分析mysql MDL元数据锁
2024-01-28 18:29:10
python 实现UTC时间加减的方法
2023-08-06 15:35:42