解决Python3中的中文字符编码的问题
作者:FANDX 时间:2022-05-04 04:22:09
python3中str默认为Unicode的编码格式
Unicode是一32位编码格式,不适合用来传输和存储,所以必须转换成utf-8,gbk等等
所以在Python3中必须将str类型转换成bytes类型的
在Python中使用encode的方式可以进行字符的编码
实际用法:
>>>a = "中国">>> a.encode("utf-8")b'\xe4\xb8\xad\xe5\x9b\xbd'>>> a.encode("gbk")b'\xd6\xd0\xb9\xfa'
总结:
Python中str类型转bytes类型,相当与Unicode转gbk,utf-8。。。类型
b'代表字符编码格式为bytes,
utf-8默认24位占3个8位16进制数
gbk中国编码默认占16位2个8位16进制数字
以上所述是小编给大家介绍的解决Python3中的中文字符编码的问题网站的支持!
来源:https://www.cnblogs.com/fandx/archive/2018/07/18/9327050.html
标签:python,中文,字符,编码
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
Python使用socket实现组播与发送二进制数据
2021-05-09 13:44:28
![](https://img.aspxhome.com/file/2023/9/65949_0s.png)
Python 使用 attrs 和 cattrs 实现面向对象编程的实践
2022-05-29 22:38:00
jupyter notebook 调用环境中的Keras或者pytorch教程
2022-10-07 23:23:09
![](https://img.aspxhome.com/file/2023/5/92525_0s.jpg)
Flask框架之数据交互的实现
2023-01-25 05:41:10
![](https://img.aspxhome.com/file/2023/7/102917_0s.png)
python中封装token问题
2022-09-29 01:09:32
Tensorflow分类器项目自定义数据读入的实现
2023-06-21 20:21:53
![](https://img.aspxhome.com/file/2023/4/59144_0s.png)
JavaScript获取时区实现过程解析
2023-08-22 20:58:34
浅谈Python反射 & 单例模式
2023-10-14 21:16:30
让表单 input 只能输入数字
2008-06-08 13:54:00
Python中PyAutoGUI帮助文档(推荐!)
2022-12-18 20:50:16
Python asyncio的一个坑
2022-04-06 20:58:28
Python编程实现使用线性回归预测数据
2022-03-07 11:28:55
![](https://img.aspxhome.com/file/2023/0/134460_0s.jpg)
python爬虫竟然被小伙用来算命
2023-08-28 17:35:20
![](https://img.aspxhome.com/file/2023/3/86663_0s.png)
Javascript实现的鼠标经过时播放声音
2010-05-18 20:03:00
python实现网络五子棋
2021-10-16 23:58:17
![](https://img.aspxhome.com/file/2023/0/93640_0s.jpg)
pytorch索引查找 index_select的例子
2023-09-12 20:45:05
使用python求解迷宫问题的三种实现方法
2022-10-25 01:16:35
![](https://img.aspxhome.com/file/2023/2/78602_0s.jpg)
Python3中的真除和Floor除法用法分析
2023-10-11 09:01:45
Python生成器传参数及返回值原理解析
2022-03-17 08:58:40
Python实现将n个点均匀地分布在球面上的方法
2021-02-21 20:56:33
![](https://img.aspxhome.com/file/2023/1/107081_0s.png)