1、asccii(一个字符占一个字节)
2、gbk(一个字符占两个字节)
3、unicode(万国码)
4、utf-8(pychrom默认的文件编码)
1、内存->磁盘(网络传输)->内存
2、unicode->utf-8->unicode
3、str->bytes->str
4、unicode->utf-8:编码 A.encode(‘utf-8‘)
5、utf-8->unicode:解码A.decode(‘utf-8‘)
1、python默认的内存编码是unicode
2、推荐使用文件编码utf-8,如无特殊需求
3、在文件头加文件编码(pycharm不需要),文本编辑器需要
# !/usr/bin/env python3 # -*- coding: utf-8 -*-
原文:https://www.cnblogs.com/wt7018/p/10744041.html